[swift-evolution] Public classes with private superclass

Charlie Monroe charlie at charliemonroe.net
Tue Jul 5 02:01:58 CDT 2016

How would this look in the exported API? Would it simply show itself as not inheriting from anything? If your base class inherited from something (e.g. NSObject), would the public subclasses show themselves as direct subclasses of that superclass (NSObject)?

IMHO these things can be solved by private protocols with default implementation to reuse the code:

internal protocol MyClassCore { }
extension MyClassCore {
	func doSomething() {

public class MyClass1 { }
extension MyClass1: MyClassCore { }

Or you can just create a private class and use its instance in your classes:

internal class MyClassImplementation {
	/// Implement shared code

public class MyClass {
	private var _impl = MyClassImplementation()

Which is fairly common solution.

Anyway, this is definitely out of scope of Swift 3 and as has been pointed out several times in the past month here, all discussions here should now focus on Swift 3 features.

> On Jul 5, 2016, at 8:49 AM, Andre via swift-evolution <swift-evolution at swift.org> wrote:
> Personally, it's perhaps more of an "aesthetic" thing I suppose but I would definitely prefer that my internal classes stay internal even if there is a public subclass... I don't like how that leaks my internal implementation like that...
> Though maybe the more swift thing to do would be to use private extensions in place of private superclasses I suppose...
> andre 
> iPhoneから送信
> 2016/07/04 21:31、Tino Heth via swift-evolution <swift-evolution at swift.org> のメッセージ:
>> I'm running into "class cannot be declared public because its superclass is internal" issues on a regular basis, and I wonder if it wouldn't make sense to allow this combination:
>> It might be less useful as soon as there are abstract classes or generic protocols, but even then I think I'd like to have this "feature".
>> Inheritance can be such a private thing ;-), so imho there should be an obvious way to hide it (marking all init-methods internal works, but I don't think this is a good way to express the intention).
>> Tino
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

More information about the swift-evolution mailing list