key-value-observing

In Swift3, KVO the alpha of a UIView?

放肆的年华 提交于 2020-01-04 03:32:27
问题 It's "easy" to KVO a value in Swift3, using the technique in this great post... https://stackoverflow.com/a/25219216/294884 How do I KVO the alpha of a UIView? Goal: imagine a screen with a small view V. Screen has a large table view. Each cell has a small view CV. I want each CV to follow 1 the alpha of V, actually during an animation of the alpha of V. (The only real alternate I can think of is to CADisplayLink the cells and poll the alpha of V, which kind of sucks.) 1 Reason for that? It's

KVO doesn't work with keypath like com.alpha.

蓝咒 提交于 2020-01-03 03:22:07
问题 My NSMutableDictionary contains simple keys (@"one", @"two", @"three") and complex keys (@"com.alpha", @"com.beta"). Is it possible to use observers for a complex key? Observers work well with simple keys, but didn't worked with complex keys. What is a solution? [self.dict addObserver:self forKeyPath:@"com.alpha" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil]; -(IBAction) onChange:(id)sender { [self.dict setObject:@"newValue" forKey:@"com.alpha"]; } -(void)

Observing a value of a static var in a class?

你。 提交于 2020-01-02 06:33:30
问题 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 , but declaring a static variable as dynamic causes an error: class ConnectionManager: NSObject { dynamic static var online = false // adding 'dynamic' declaration causes error: // "A declaration cannot be both 'final' and 'dynamic' } What is a most elegant way of doing this? Update . This my code for

Safe Key Value Observing of keypaths

﹥>﹥吖頭↗ 提交于 2020-01-01 19:59:34
问题 I am trying to implement a safe key value observing on keypaths. Let's suppose that I have a data model object named person that have a workplace property. The workplace in turn have a address property that I wish to observe so I set up key value observing with the following call: [person addObserver:theObserver forKeyPath:@"workplace.address" options:NSKeyValueObservingOptionNew context:NULL]; This works fine until the person does not change workplace. As soon as this happens: person

Safe Key Value Observing of keypaths

北城余情 提交于 2020-01-01 19:59:02
问题 I am trying to implement a safe key value observing on keypaths. Let's suppose that I have a data model object named person that have a workplace property. The workplace in turn have a address property that I wish to observe so I set up key value observing with the following call: [person addObserver:theObserver forKeyPath:@"workplace.address" options:NSKeyValueObservingOptionNew context:NULL]; This works fine until the person does not change workplace. As soon as this happens: person

key value observers were still registered with it when controller is deallocated

心不动则不痛 提交于 2020-01-01 06:32:24
问题 I added an observer in the code and then removed it in dealloc and viewWillDisappear but still i am getting an error stating *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x167e5980 of class MyController2 was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x16719f90> ( <NSKeyValueObservance 0x16719fb0: Observer: 0x167e5980, Key path: dataContainer.report, Options

KVO on an NSCountedSet?

拜拜、爱过 提交于 2020-01-01 06:21:53
问题 I'd like to monitor an NSCountedSet to see if its contents changes. Setting up KVO seems to compile but it's not being triggered. First question: can you observe a set? If so then is there something wrong with this message? [subViewA addObserver:subViewB forKeyPath:@"countedSet" options:0 context:NULL]; I'm really just trying to monitor the count of (number of objects in) the set if that helps. Edit - here's the observer (subViewB): - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:

KVO on an NSCountedSet?

落爺英雄遲暮 提交于 2020-01-01 06:18:43
问题 I'd like to monitor an NSCountedSet to see if its contents changes. Setting up KVO seems to compile but it's not being triggered. First question: can you observe a set? If so then is there something wrong with this message? [subViewA addObserver:subViewB forKeyPath:@"countedSet" options:0 context:NULL]; I'm really just trying to monitor the count of (number of objects in) the set if that helps. Edit - here's the observer (subViewB): - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:

Key-Value-Observing a to-many relationship in Cocoa

谁都会走 提交于 2019-12-28 03:38:11
问题 I am trying to get key-value-observing to work for an NSMutableArray. Below is the .h file for MyObservee, the observed class: @interface MyObservee : NSObject { @private int someValue; @private NSMutableArray *someArray; } @property (readwrite,assign) int someValue; - (NSMutableArray *)someArray; @end The class MyObserver implements observeValueForKeyPath:ofObject:change:context:. Here is how I add the observer: MyObservee *moe = [[MyObservee alloc] init]; MyObserver *mobs = [[MyObserver

Why would you use an ivar?

落花浮王杯 提交于 2019-12-27 10:36:07
问题 I usually see this question asked the other way, such as Must every ivar be a property? (and I like bbum's answer to this Q). I use properties almost exclusively in my code. Every so often, however, I work with a contractor who has been developing on iOS for a long time and is a traditional game programmer. He writes code that declares almost no properties whatsoever and leans on ivars. I assume he does this because 1.) he's used to it since properties didn't always exist until Objective C 2