[swift-evolution] classprivate protection level?

Noah Desch deschnl at icloud.com
Sun Oct 29 11:13:51 CDT 2017


Internal is the best choice available at the moment but I wouldn’t call it the “right” choice. Languages with the concept of classes often have a “protected” scope with means “visible within this class and subclasses”. In Swift that could mean “visible within this class, subclasses, and extensions” which would also make it useful for structs/enums, etc. I’ve also wanted such an access level on numerous occasions.


> On Oct 29, 2017, at 12:04 PM, Adam Kemp via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Internal is the right choice here. If it gives too much access then you might consider pulling this code into a separate module.
> 
> If “private” gave access to every extension then any code outside your module could make a new extension and access that method. That would make it effectively public in that you wouldn’t have any ability to limit who can call it.
> 
> On Oct 29, 2017, at 7:37 AM, Mike Kluev via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> i am missing some protection level, which can be called "classprivate" or "structprivate" / "enumprivate" (names could be better). here is an example:
>> 
>> --- file Some.swift ---
>> 
>> class Some {
>> 	private func foo() {
>> 		bar() // error: inaccessible due to 'private'
>> 	}
>> }
>> 
>> --- file Some+Bar.swift ---
>> 
>> extension Some {
>> 	private func bar() {
>> 		foo() // error: inaccessible due to 'private'
>> 	}
>> }
>> 
>> 1) i want to have this extension in a different file (to keep file sizes manageable).
>> 
>> 2) i can't use either private or fileprivate due to compilation errors
>> 
>> 3) i do not want to have neither "foo" nor "bar" public
>> 
>> 4) "internal" doesn't help as "foo" and "bar" will be available to my app (which is unwanted).
>> 
>> is there some "classprivate" to help here? if not so far, shall there be one? opinions?
>> 
>> Mike
>> 
>> _______________________________________________
>> 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