Created
November 5, 2016 01:43
-
-
Save wh1pch81n/2f25c215e5c8f78853a141abff6b96cc to your computer and use it in GitHub Desktop.
Swift has no access modifier "Protected". Below is the closest thing to protected. You can call this semi-protected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
// discourage directly setting property m by using private(set). Anyone can still set the value of the property via setValue(_ :forKey:) | |
public class Abe: NSObject { | |
public private(set) var m: [String] = ["abc"] | |
} | |
public class Billy: Abe { | |
override init() { | |
super.init() | |
setValue(["abc", "def", "ghi"], forKey: "m") | |
} | |
} | |
Abe().m // ["abc"] | |
Billy().m // ["abc", "def", "ghi"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment