facebookarchive / KVOController

Simple, modern, thread-safe key-value observing for iOS and OS X.
Other
7.34k stars 925 forks source link

is there any scenario for using `KVOControllerNonRetaining`? #136

Open sjtupt opened 6 years ago

rjinxx commented 6 years ago
[self.KVOController observe:self keyPath:@"date" options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionNew action:@selector(updateClockWithDateChange:)];

like this, you observe 'self', if you're not using KVOControllerNonRetaining you'll get retain cycle issue

sjtupt commented 6 years ago

@RylanJIN got it. Thank you.

djs66256 commented 4 years ago

KVOControllerNonRetaining is an ambiguous api.

[self.KVOControllerNonRetaining observe:self keyPath:@"date" options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionNew action:@selector(updateClockWithDateChange:)];

It will crash. When self dealloc, weak table has already removed the self pointer, so you can not remove observer forever.