Access Control in Fast 4

When upgrading to Swift4from Swift3, I had some problems related to access control.

Here is a sample code. What was in Swift3worked great in the past -

open class MyClass {
    private let value: Int
    static var defaultValue: Int { return 10 }
    public init(value: Int = MyClass.defaultValue) {
        self.value = value
    }
}

To execute the code Swift4, I need to change access controlto defaultValueon public. Here Swift4is the compiling version

open class MyClass {
    private let value: Int
    static public var defaultValue: Int { return 10 }
    public init(value: Int = MyClass.defaultValue) {
        self.value = value
    }
}

While I was wondering what was going on, I tried to remove the control openfor MyClass, this allowed me to remove the identifier accessfor defaultValue. You can even put it on private.

class MyClass {
    private let value: Int
    private static var defaultValue: Int { return 10 }
    public init(value: Int = MyClass.defaultValue) {
        self.value = value
    }
}

I understand all access identifiers, but I cannot understand this behavior. Especially the first time that xcodemade me change access controlfrom defaultValueto public.

, .

+4
1

, (@_inlineable, @_versioned, @_fixed_layout), ( , , ). , .

, - , , , . (i.e public ).

, , - , inlineable, , . , ; .

, Swift 4, - Swift , :

Swift 3.1 , , Swift 4 .

, (, MyClass.defaultValue ), , . defaultValue .

, private ( ). , , @_versioned, (file)private - :

, @_versioned private fileprivate, , :

  • "", . , ABI, - .

  • , @_versioned - ABI . , private @_versioned, , public.

"private versioned". , internal .

@_versioned var defaultValue, :

open class MyClass {

    private let value: Int

    @_versioned static var defaultValue: Int {
        return 10
    }

    public init(value: Int = MyClass.defaultValue) {
        self.value = value
    }
}

MyClass.defaultValue , - ( internal). . , , , , ; , .

+4
source

Source: https://habr.com/ru/post/1686747/


All Articles