Re: [swift-evolution] constant var

2017-12-14 Thread Joe Groff via swift-evolution
> On Dec 14, 2017, at 12:51 AM, Inder Kumar Rathore . > wrote: > > class MyClass { > private var myDict = [String : String]() > > func addMemebr() { > self.myDict["key"] = "value" // Ok for me > } > > func anotherFunc() { > self.myDict = [String :

Re: [swift-evolution] constant var

2017-12-14 Thread Magnus Ahltorp via swift-evolution
> 14 Dec. 2017 09:52 Inder Kumar Rathore . via swift-evolution > wrote: > > class MyClass { > private var myDict = [String : String]() > > func addMemebr() { > self.myDict["key"] = "value" // Ok for me > } > > func anotherFunc() { > self.myDict

Re: [swift-evolution] constant var

2017-12-14 Thread Nick Keets via swift-evolution
What are you going to do about this then? func thirdFunc() { self.myDict.removeAll() } Is this ok or not? Is it really different from `anotherFunc`? On Thu, Dec 14, 2017 at 10:52 AM, Inder Kumar Rathore . via swift-evolution wrote: > class

Re: [swift-evolution] constant var

2017-12-14 Thread Magnus Ahltorp via swift-evolution
> 14 Dec. 2017 17:52 Inder Kumar Rathore . via swift-evolution > wrote: > > class MyClass { > private var myDict = [String : String]() > > func addMemebr() { > self.myDict["key"] = "value" // Ok for me > } > > func anotherFunc() { > self.myDict

Re: [swift-evolution] constant var

2017-12-14 Thread Inder Kumar Rathore . via swift-evolution
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 } } On Tue, Dec 12,

Re: [swift-evolution] constant var

2017-12-12 Thread Joe Groff via swift-evolution
> On Dec 11, 2017, at 11:34 PM, Inder Kumar Rathore . via swift-evolution > wrote: > > 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

Re: [swift-evolution] constant var

2017-12-12 Thread BJ Homer via swift-evolution
If I understand correctly, you want to be able to modify myDict from within MyClass, but not from outside it. In that case, you’re looking for private(set). class MyClass { private(set) var myDict = [String : String]() } -BJ > On Dec 12, 2017, at 12:34 AM, Inder Kumar Rathore . via

Re: [swift-evolution] constant var

2017-12-12 Thread Kelvin Ma via swift-evolution
here’s the problem. if your type is an inline type (ie a struct or an enum), modifying a member of your object is really modifying part of the entire variable. so, declaring the variable as let makes no sense. if your type is an indirect type (a class), modifying a member of your object is really

Re: [swift-evolution] constant var

2017-12-12 Thread Austin Zheng via swift-evolution
Ugliness is preferable to the alternative of impossibility because what you are trying to do and the semantics of the type you are trying to do it with are irreconcilably and mutually exclusive. > On Dec 12, 2017, at 12:00 AM, Inder Kumar Rathore . via swift-evolution >

Re: [swift-evolution] constant var

2017-12-12 Thread Inder Kumar Rathore . via swift-evolution
Nice idea but I think the code will look ugly On Tue, Dec 12, 2017 at 1:28 PM, Rafael Guerreiro wrote: > You actually need a class to wrap the dictionary. > That’s because dictionaries are struct, with copy-on-write. > > With a class, you’ll be able to have it mutable,

Re: [swift-evolution] constant var

2017-12-11 Thread Rafael Guerreiro via swift-evolution
You actually need a class to wrap the dictionary. That’s because dictionaries are struct, with copy-on-write. With a class, you’ll be able to have it mutable, in a let declaration. On Mon, Dec 11, 2017 at 11:34 PM Inder Kumar Rathore . via swift-evolution < swift-evolution@swift.org> wrote: > Hi

[swift-evolution] constant var

2017-12-11 Thread Inder Kumar Rathore . via swift-evolution
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