> 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 :
> 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
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
> 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
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,
> 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
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
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
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
>
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,
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
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
12 matches
Mail list logo