Questions tagged [key-value-observing]

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

1201 questions
0
votes
1 answer

Observing Multiple NSKeyObservingKeyValueoptions swift

How to observe multiple NSKeyObservingKeyValueoptions in swift self.avplayerItem.addObserver(self, forKeyPath: "status", options:[.Initial | .New], context: nil) I get an error like Error No '|' candidates produce the expected contextual result…
hariszaman
  • 8,202
  • 2
  • 40
  • 59
0
votes
1 answer

Using KVO to observing view.center in swift for ios give back NSPoint?

Here is the code view.addObserver(self, forKeyPath: "center", options: .New, context: nil) override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer) { …
Morty Choi
  • 2,466
  • 1
  • 18
  • 26
0
votes
2 answers

If I am observing a collection via KVO, am I notified of changes to objects within the collection?

I assume not, but always like to double check. Let's say I have an NSMutableArray I'm KVObserving. It holds a bunch of Employee object. If I fully assign the array, then no doubt I'll observe the change. However, what if I change one of the Employee…
chris P
  • 6,359
  • 11
  • 40
  • 84
0
votes
1 answer

how can i auto update value of bool variable

i have one bool variable isValidSession i want to observer this variable in whole application whenever it becomes false it will automatically call method and renew the session. override func observeValueForKeyPath(keyPath: String?, ofObject object:…
Janak Thakkar
  • 414
  • 5
  • 20
0
votes
1 answer

Is it possible to observer a NSMutableArray from different class?

I'll try to summarize this as succinctly as possible: I have three classes: a ViewController, a ViewModel, and a DataSource. The ViewController creates both the ViewModel and DataSource. It then proceeds to "configure" the DataSource with a…
0
votes
1 answer

KVO conditionally fire method in observeValueForKeyPath

I have a countdown that counts down from 5. I use KVO on a float property that represents the countdown. It fires observeValueForKeyPath once or not at all. I want it fire observeValueForKeyPath until the property being observed matches a particular…
noobsmcgoobs
  • 2,716
  • 5
  • 32
  • 52
0
votes
1 answer

Is it safe to use Interface Builder bindings to observe properties changed on non-main thread?

If I use Interface Builder to bind, e.g. NSTextField's value to someObject.property and this property (assuming it's assign, atomic type) will change from a non-main thread, will this be safe/correct? Cocoa generally forbids updating UI from…
Kornel
  • 97,764
  • 37
  • 219
  • 309
0
votes
2 answers

Using KVO in a block function

Is there a good way to use key-value-observation and blocks together? I have a function that takes a completion block, and I want this completion block to run when the observed status changes into AVPlayerItemStatusReadyToPlay. Can I pass the block…
Daniel Larsson
  • 6,278
  • 5
  • 44
  • 82
0
votes
1 answer

keyValue observer from cell to managed object

I am looking at a table view cell here and I find this code: - (void)awakeFromNib { [super awakeFromNib]; [self addObserver:self forKeyPath:@"model.isDownloading" options:NSKeyValueObservingOptionNew context:NULL]; [self addObserver:self…
thst
  • 4,592
  • 1
  • 26
  • 40
0
votes
1 answer

I needed to listen out for changes to a UIScrollView but I couldn’t set the delegate in swift

I recently found myself in a situation where I needed to listen out for changes to a UIScrollView of which I couldn’t set the delegate. I have 2 views, they all want to be delegate of the scrollView but it only can set one view, how about the second…
rose
  • 241
  • 5
  • 16
0
votes
2 answers

iOS: Animation Not working in observeValueForKeyPath

I used KVO to observe changes in a frame and set another frame accordingly - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{ if ([keyPath…
Amr Lotfy
  • 2,937
  • 5
  • 36
  • 56
0
votes
1 answer

Objective C KVO, NSLog New + Old values

I have: - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(Player *)object change:(NSDictionary *)change context:(void *)context { switch…
0
votes
0 answers

IOS KVO work wrong

At first sorry for my english. So i faced with strange kvo behavior. I have a class A with property "propA" of class B; class B have property "propB". So i want class A to watch property "propB". But when i add observer self from class A for keypath…
Ar4ibald
  • 3
  • 1
0
votes
2 answers

Remove all observers from a class

In a project I have a class say "A", there are many other class that are observing class "A"'s property values. Sometimes the class "A" instance gets deallocated and observees fails resulting in crash! Is there any way to remove all the observers…
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
0
votes
1 answer

Crashreport indicates KVO connection between object and parameter which was never initiated in code

Recently I have gotten some very strange crashes on HockeyApp: Application Specific Information: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x13ef90530 of class FPPhoto was deallocated…
knutigro
  • 1,082
  • 2
  • 10
  • 20