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
Regard
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
> wrote:
>
>
It seems like a bug. You should file it.
Zhaoxin
On Sun, Sep 4, 2016 at 11:11 PM, wrote:
> 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
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 paramet
> 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 bug to me. The book exp
Hi,
didSet is called as soon as the property is stored… Excepted when the value is
stored in the initialiser code.
For me it is completely predictable that your code enter an infinite loop
Regards
> On 4 Sep 2016, at 17:11, adelzhang via swift-users
> wrote:
>
> Thanks for reply.
>
> How
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 {
>
> 1) when `didSet` observer will call?
For me, it is more like Swift developer tries to override some beginner's
> flaw.
Above is incorrect. You can change property's value in `didSet`, that won't
cause didSet called again as it is intended to give you the opportunity to
do that.
2) infini
>
> 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 says
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
10 matches
Mail list logo