What is a good example to differentiate between fileprivate and private in Swift3

前端 未结 10 1057
醉梦人生
醉梦人生 2020-11-27 10:03

This article has been helpful in understanding the new access specifiers in Swift 3. It also gives some examples of different usages of fileprivate

10条回答
  •  粉色の甜心
    2020-11-27 10:32

    filePrivate - access controll level is within the file.

    case 1: If we create extension with in same class file and try to access fileprivate function or fileprivate property in its extension - access allowed
    case 2: If we create a extension of class in new file - And now try to access fileprivate function or fileprivate property - access not allowed

    private - access control level is with in lexical scope

    case 1: If property or function is declared as private in class - then scope is by default the class. case 2: if private instance is declared with in function body - then scope of instance is limited to function body.

提交回复
热议问题