Questions tagged [key-value-observing]

Key-value Observing or KVO is a technology for observing changes in object properties.

1201 questions
19
votes
2 answers

Error with: override public func observeValueForKeyPath

I am using code that worked with Xcode 7 Beta 2. Just got Beta 3 and now I'm getting this problem that seems like an Xcode bug? For one of my public classes... override public func observeValueForKeyPath... Method does not override any method from…
36 By Design
  • 3,203
  • 3
  • 18
  • 18
19
votes
3 answers

Crash with removeObserver:forKeyPath: in Foundation

I having some problems with the following crash logs retrieved from the "Crashes" section in Xcode. Only few devices are affected by this crash report. I have analyzed the problem but I guess it's a bug on Apple framework. But I cannot find a way to…
Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
19
votes
2 answers

Key Value Observing - how to observe all the properties of an object?

I am happy with the use of Key Value Observing (KVO), and how to register to receive notifications of property change: [account addObserver:inspector forKeyPath:@"openingBalance" options:NSKeyValueObservingOptionNew …
ColinE
  • 68,894
  • 15
  • 164
  • 232
19
votes
2 answers

Observing Changes to a mutable array using KVO vs. NSNotificationCenter

In my model I have an array of objects called events. I would like my controller to be notified whenever a new object is added to events. I thought that a good way to do this would be use the KVO pattern to get notified when the events changes (from…
18
votes
4 answers

iOS: How do I know if a property is KVO-compliant?

In the Key-Value Observing Programming Guide, the section Registering for Key-Value Observing says "Typically properties in Apple-supplied frameworks are only KVO-compliant if they are documented as such." But, I haven't found any properties in the…
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
18
votes
1 answer

observeValueForKeyPath not being called

I have a ViewController creating an instance of a UIView, and then I register an observer with the instance, such that logoAnimation = [[MainLogoAnimation alloc] init]; [logoAnimation addObserver:self forKeyPath:@"patrocinioDidLoad"…
Antonio
  • 863
  • 1
  • 11
  • 23
17
votes
2 answers

Objective C:Object Deallocated while key value observers were still registered with it

I am hitting the below error after I added 2 additional fields to my core data model. CarPark_CarPark_ was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to…
Zhen
  • 12,361
  • 38
  • 122
  • 199
17
votes
2 answers

NSKeyValueObservation: Cannot remove an observer for the key path from object because it is not registered as an observer

I get random crashes (which I can't reproduce on devices I own) in my app with exception: Cannot remove an observer Foundation.NSKeyValueObservation 0xaddress for the key path "readyForDisplay" from AVPlayerLayer 0xaddress because it is not…
iur
  • 2,056
  • 2
  • 13
  • 30
17
votes
2 answers

Receiving 2 KVO notifications for a single KVC change

I'm using KVC/KVO to create a custom bindings implementation for a University project (it needs to be custom as I want to do things beyond what bindings can do, including running on iOS). I have a 'bindings controller' that registers for KVO…
extremeboredom
  • 1,512
  • 12
  • 13
16
votes
2 answers

Swift 4 Using KVO to listen to volume changes

I just updated to Swift 4 and Xcode 9 and got a (swiftlint) warning for the following code telling me that I should use KVO now: Warning: (Block Based KVO Violation: Prefer the new block based KVO API with keypaths when using Swift 3.2 or later.…
Eternal Black
  • 259
  • 2
  • 15
16
votes
1 answer

Cocoa key value observing a key/entry in a dictionary

Is it possible to observe a specific key in a dictionary? If so how can I do it?
Justin Meiners
  • 10,754
  • 6
  • 50
  • 92
16
votes
3 answers

Swift 4 (BETA 2) KVO crashing, based upon WWDC talk

I am trying to get something very similar to the example in the WWDC 2017 Foundation talk working for KVO observing. The only differences that I see that are different from that talk are, I had to call super.init(), and I had to make the "kvo" token…
possen
  • 8,596
  • 2
  • 39
  • 48
16
votes
4 answers

Observe changes in a UIView's subviews array with KVO

I have looked around all over for an answer to this and I have tried to implement it, but nothing is working. Basically, I need to be able to observe changes in a VC view's subviews array. If an existing view is removed from that array, I want to be…
Lizza
  • 2,769
  • 5
  • 39
  • 72
16
votes
2 answers

Objective-C variable... pointing to itself?

I spotted this construct in some of Apple's example code for dealing with key-value observing. When adding an observer, you can add a context (in the form of a void* variable) that can uniquely identify the KVO call - particularly useful if you want…
jstm88
  • 3,335
  • 4
  • 38
  • 55
15
votes
1 answer

How reliable is KVO with UIKit

Important: Not all classes are KVO-compliant for all properties. You can ensure your own classes are KVO-compliant by following the steps described in “KVO Compliance.” Typically properties in Apple-supplied frameworks are only…
Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105
1 2
3
80 81