Re: [swift-users] strange property observer behavior

2016-09-04 Thread adelzhang via swift-users
Hi, The following code works fine. The property `a` is stored twice. But it don't enter infinite loop. class Foo { var a: Int = 0 { didSet { a = a + 1 } } } let foo = Foo() foo.a = 2 print(foo.a) // output 3

Re: [swift-users] Data withUnsafeBytes

2016-09-04 Thread Chris McIntyre via swift-users
That makes sense. I think I've gotten so used to the type system magically figuring out what I want, combined with the error message pointing to the return type that this just went right over my head. -- Chris McIntyre > On Sep 4, 2016, at 3:59 PM, Ole Begemann via swift-users >

Re: [swift-users] Data withUnsafeBytes

2016-09-04 Thread Ole Begemann via swift-users
The compiler has no way of inferring the type of the generic ContentType parameter because you're not using that parameter anywhere in the body of the closure that could give the compiler a hint. So you have to provide the type manually by explicitly annotating the type of the closure's

Re: [swift-users] strange property observer behavior

2016-09-04 Thread Jens Alfke via swift-users
> On Sep 4, 2016, at 8:11 AM, adelzhang via swift-users > wrote: > > Swfit encourage to override the property observer. But when we change the own > property in Child class's `didSet` observer, that would cause infinite loop: I’m not a Swift guru, but that seems like a

Re: [swift-users] strange property observer behavior

2016-09-04 Thread adelzhang via swift-users
Thanks for reply. How does Swift choose *rules* as you said? Swfit encourage to override the property observer. But when we change the own property in Child class's `didSet` observer, that would cause infinite loop: class Base { var a: Int = 0 } class Child : Base {

Re: [swift-users] strange property observer behavior

2016-09-04 Thread Zhao Xin via swift-users
> > 1) when `didSet` observer will call? ​For me, it is more like Swift developer tries to override some beginner's flaw. ​2) infinite loop ​If you intended to do things bad, things ​went bad. 3) override property observer ​You mentioned "TSPL(The Swift Programming Language) ​", and it

[swift-users] strange property observer behavior

2016-09-04 Thread adelzhang via swift-users
Hi all It sounds convenient to monitor change in property's value using property observer. But TSPL(The Swift Programming Language) talk little about property observer. There are some questions abouts property observer. 1) when `didSet` observer will call? I assume it's fine that changing