[swift-evolution] constant var
Inder Kumar Rathore .
rathore619 at gmail.com
Tue Dec 12 01:33:25 CST 2017
Hi All,
Today I was writing code and faced a situation where I need to make a
instance variable a const i.e. it shouldn't accept new values from anywhere
but the problem is that I want it's content to be mutable.
e.g.
class MyClass {
var myDict = [String : String]()
}
I want above variable to be constant and if I make it like below
class MyClass {
let myDict = [String : String]()
}
Then I cann't add key/value in the myDict like
self.myDict["name"] = "Rathore"
I know swift and couldn't find anything related to this.
Can anybody help me?
If there is no such method of doing it then I would suggest to either use a
syntax like
class MyClass {
const var myDict = [String : String]()
}
I'm not using *final *here since that make a var not overridable.
--
Best regards,
Inder Kumar Rathore
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171212/7f8495da/attachment.html>
More information about the swift-evolution
mailing list