> 14 Dec. 2017 09:52 Inder Kumar Rathore . via swift-evolution > <swift-evolution@swift.org> wrote: > > class MyClass { > private var myDict = [String : String]() > > func addMemebr() { > self.myDict["key"] = "value" // Ok for me > } > > func anotherFunc() { > self.myDict = [String : String]() // Not okay for me, I don't want any > code to do this within the class > } > }
Let me take another example, if we write this extension to Int: extension Int { subscript(bit: Int) -> Bool { get { return get_bit_value(self, bit) } set { self = set_bit_value(self, bit, newValue) } } } this wouldn't be meaningful, right? class MyClass { private var myInt : Int = 0 func addMember() { self.myInt[10] = true // Ok for me } func anotherFunc() { self.myInt = 3 // Not okay for me, I don't want any code to do this within the class } } There is no conceptual difference between Dictionary and Int here. /Magnus _______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution