key-value-observing Questions

5

Solved

I need to track the update in a variable of struct type. Is it possible to add an observer on struct variable in Swift? Example: struct MyCustomStruct { var error:Error? var someVar:String? } ...
Thebaid asked 17/1, 2019 at 8:29

4

I'm trying to use RxSwift for binding in MVVM. I have a Enum: enum Color : Int { case Red = 0, Green } and class for test class Test : NSObject { var color: Color = .Red dynamic var test: St...
Reeve asked 16/3, 2016 at 9:31

11

Solved

If you tell an Objective-C object to removeObservers: for a key path and that key path has not been registered, it cracks a sad, like: Cannot remove an observer <observerObject> for the key ...
Grave asked 17/10, 2009 at 15:0

4

I'm getting the following in my output window when running a project: An -observeValueForKeyPath:ofObject:change:context: message was received but not handled. Key path: connection.messageQueue Ob...
Domeniga asked 4/9, 2012 at 19:52

1

Solved

I've been looking for a way to trigger a method when the number of displays connected to a mac changes. I know I can get the value of NSScreen.screens.count, but I need to find a way to create a no...
Riannon asked 24/11, 2021 at 21:41

2

Solved

I am having trouble with the new observe API in Swift 4. player = AVPlayer() player?.observe(\.currentItem.status, options: [.new], changeHandler: { [weak self] (player, newValue) in if let statu...
Gwenora asked 24/9, 2018 at 8:40

4

Solved

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 ex...
Peachy asked 6/11, 2014 at 18:35

5

Solved

I'm rewriting parts of an app, and found this code: fileprivate let defaults = UserDefaults.standard func storeValue(_ value: AnyObject, forKey key:String) { defaults.set(value, forKey: key) de...
Robillard asked 14/5, 2017 at 11:13

6

Solved

I have some idea of which to use when but the exact usage is still not clear to me. Can someone explain with example?

3

Solved

Is KVO on a computed property possible in Swift? var width = 0 var height = 0 private var area : Double { get { return with * height } } self.addOberser(self, forKeyPath: "area", ...... Wou...

4

Solved

There is the observationInfo method which returns information of bindings of an object. I have looked around but i do not know how to get the information from the dictionary. Can any one lead me in...
Slacken asked 11/7, 2013 at 16:40

2

Solved

If I store an observer like this: let observer: NSKeyValueObservation = foo.observe(\.value, options: [.new]) { (foo, change) in print(change.newValue) } How do I remove/disable/cleanup observe...
Paratrooper asked 5/10, 2017 at 17:33

4

Solved

I have a box that the user is able to pan around. For that, I add an observer to check if it's center has changed: self.boxView!.addObserver(self, forKeyPath: "center", options: .old, context: &am...
Amyl asked 11/9, 2018 at 12:34

3

Solved

Apples documentation alludes to it, but how do you set up key-value observation for the loadedTimeRanges property of AVPlayerItem? That property is an NSArray that doesn't change, so you can't just...
Babul asked 25/1, 2012 at 0:27

3

I use the following code to add KVO on object. [self.model addObserver:self forKeyPath:@"userName" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil]; Now I wan...
Seductive asked 27/1, 2013 at 0:45

2

Solved

I have a custom NSManagedObject subclass, say, Person. I also have a UIView registered with -addObserver:forKeyPath:options:context: to observe various properties of a Person, some of which are per...
Resuscitator asked 16/9, 2010 at 15:32

4

Solved

I have a class with a static var where the current online connection status is stored. I want to observe the value of ConnectionManager.online through other classes. I wanted to do this with KVO, b...
Theotokos asked 6/7, 2016 at 22:34

2

Solved

Why can't I observe the editing property of an instance of UITableViewController? I'm using the following code: [self addObserver:self forKeyPath:@"editing" options:(NSKeyValueObservi...

2

Solved

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:NSKeyVa...
Kostroma asked 21/11, 2012 at 10:40

3

Solved

Is it possible to add an observer to get notified if any of the monitored object properties is modified? For example: @interface OtherObject : NSObject @property (nonatomic) MyObject* myObject; ...
Onshore asked 1/10, 2012 at 12:33

9

Solved

I want to watch for changes in a UIView's frame, bounds or center property. How can I use Key-Value Observing to achieve this?
Togoland asked 2/2, 2011 at 12:8

3

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 g...
Matchwood asked 11/5, 2015 at 10:17

11

Solved

If so, are there any key differences that weren't otherwise present when using key-value observation in Objective-C?
Paeon asked 7/6, 2014 at 0:5

4

Solved

I'm trying to observering collectionView.contentSize like this : func startObserveCollectionView() { collectionView.addObserver(self, forKeyPath: "contentSize", options: NSKeyValueObservingOption...
Topless asked 15/7, 2015 at 4:14

5

Solved

I am relatively new to KVO, so there is a good chance that I am violating some fundamental rule. I am using Core Data. My app crashes with the following message: And what I can't understand is why...
Audile asked 8/11, 2010 at 0:46

© 2022 - 2024 — McMap. All rights reserved.