[swift-evolution] Class scoped access level

Tom Bates tbatesuk at gmail.com
Fri Sep 9 10:49:29 CDT 2016


There is currently no way of accessing "shared code" from extensions
declared outside the base .swift file

I would love to see along side the new fileprivate access level a
classprivate access level that would allow any extension declared outside
of the original .swift file to access these properties and functions in an
attempt to reuse code.

an example is below...

=================
//MyClass.swift
public class MyClass {

classprivate func sharedFunction() {
  self.function1()
  self.function2()
}

fileprivate func function1() {}
fileprivate func function2() {}
}
=================

=================
//MyClass+Save.swift
extension MyClass {

public func save() {
  self.someFunction()
  self.sharedFunction()
}

fileprivate func someFunction() {}
}
=================

Currently to achieve anything like this you would have to make the "core"
functions public or internal or write the whole thing in a single file
which as I understand it is not optimal for the compile speed and can get
unmanageable for large classes. This would allow a more managed file
structure and the separation of related functions from the core declaration.

There would be no migration needed I don't think as the impact on current
code would be zero until the developer adopts the new access level

Regards,
Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160909/e732f8bb/attachment.html>


More information about the swift-evolution mailing list