Can't use private property in extensions in another file

后端 未结 2 1216
被撕碎了的回忆
被撕碎了的回忆 2021-01-04 01:54

I can\'t use private property in extension. My extension is in another file.

How can I use private property in extension?

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-04 02:28

    Update Starting with Swift 4, extensions can access the private properties of a type declared in the same file. See Access Levels.

    If a property is declared private, its access is restricted to the enclosing declaration, and to extensions of that declaration that are in the same file.

    If the property is declared fileprivate, it can only be used within the file it is declared (and by anything in that file).

    If the property is declared internal (the default), it can only be used within the module it is declared (and by anything in that file).

    If the property is declared public or open, it can be used by anything within the module as well as outside of the module by files that import the module it is declared in.

提交回复
热议问题