key-value-observing

How to observe the value of an NSTextField

我怕爱的太早我们不能终老 提交于 2019-12-14 03:57:31
问题 This might seem straightforward, but the following code does not work, because the "observeValueForKeyPath" function is never called, although I keep changing the text in the NSTextfield: - (void)awakeFromNib { [myNSTextField addObserver:self forKeyPath:@"value" options:NSKeyValueObservingOptionOld context:nil]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { NSLog(@"observeValueForKeyPath"); } The log message @

SWIFT - KVO in xcode 6 beta 6.. observeValueForKeyPath no longer called

倖福魔咒の 提交于 2019-12-14 03:53:09
问题 I have been debugging my app from beta 3 to beta 6 I cannot seem to get observeValueForKeyPath to be called.. i put a breakpoint at the top of the function and nothing happens self.gameScene.viewController.joystick.addObserver(self, forKeyPath: "relativePosition", options: .New, context: nil) override func observeValueForKeyPath(keyPath: String!, ofObject object: AnyObject!, change: [NSObject : AnyObject]!, context: UnsafeMutablePointer<Void>) { if keyPath == "relativePosition" { // some code

make NSUndoManager ignore a property of an NSManagedObject

廉价感情. 提交于 2019-12-13 17:07:44
问题 My app's main function is to arrange objects on a plot. The whole thing is based on Core Data, and each object on the plot is represented by an entity. For this example, that entity will be "Unit," a custom subclass of NSManagedObject. When the plot is opened, each Unit gets a UnitViewController created, which KVO-observes changes to the Unit's properties, such as .positionX, .positionY, and .angle. Touch gestures that the UnitViewController detect modify the Unit object, and the view

When should I call removeObserver:forKeyPath from within a closing ViewController class that is observing a persistant Model class?

时光毁灭记忆、已成空白 提交于 2019-12-13 13:13:04
问题 I have a ViewController class that has a property that is the model which I want to observe as properties on the model change. Within my model object I have a property that is periodically updated in the background of my application. As it updates, I need to execute code within my ViewController . To do this, I create an observer on my model from within my ViewController viewDidLoad method. [ModelObject addObserver:self forKeyPath:@"State" options:NSKeyValueObservingOptionNew context:nil]; As

KVO versus NSNotifications [duplicate]

杀马特。学长 韩版系。学妹 提交于 2019-12-13 11:57:41
问题 This question already has an answer here : NSNotification VS KVO (1 answer) Closed 5 years ago . Is there any advantage to use KVO instead of the more "generic" (and to my opion more robust) feature of NSNotification s ? 回答1: I hate KVO with passion, mainly because it forces me to route all KVO notifications through a single handler. I use whatever else available if I have the choice. But KVO has the distinct advantage of being available for many of the classes in the standard library – if

Registering a bool for a NSNotification

二次信任 提交于 2019-12-13 05:16:30
问题 I'm trying to wrap my head around NSNotification but can't seem to get it to work. Think I'm misunderstanding how to register for an notification. I have a bool as a property in my connection manager class. At initialisation I authenticate with a few servers and check if I can access an external URL (App will mainly be used on company intranet and an external connection isn't always possible) The BOOL property will be changed from YES to NO if it cannot access the connection and as this can

iOS WatchKit - Adding Key Value Observer to NSUserDefaults crashes

倖福魔咒の 提交于 2019-12-13 04:27:38
问题 I am trying to add the ability to send data from iPhone to Watch. I have setup App Groups and everything runs smoothly, but when I try to add an observer to NSUserDefaults in the Watch Extension file, the app always crashes on startup. (And yes, I have verified that the app group name is correct and checked in all Target Capabilities AND all provisioning profiles are up-to-date with App Group enabled) Code: override func willActivate() { super.willActivate() NSUserDefaults(suiteName: "my

What's a good way to make a one-shot KVO observation?

不问归期 提交于 2019-12-13 02:35:24
问题 I want to add a KVO observation that removes itself after it fires once. I have seen lots of folks on StackOverflow doing stuff like this: - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([keyPath isEqualToString:@"myKeyPath"]) { NSLog(@"Do stuff..."); [object removeObserver:self forKeyPath:@"isFinished"]; } else { [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } } This

Using KVO within a tableview cell to track changes to specific properties of a class instance in Swift 3

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 23:29:08
问题 I'm trying to use KVO to track changes to the properties of my Account object, the important part of which looks like this: class Account: NSObject { var battleTagLabel: String! dynamic var onlineStatusIcon: String! dynamic var currentGameIcon: String! dynamic var currentStatusLabel: String! I want to be notified within my tableview cell when those three properties change in value. My tableview cell class: import Foundation import UIKit private var observerContext = 0 class FriendAccountCell:

How to typecast an id to a concrete class dynamically at runtime?

时光怂恿深爱的人放手 提交于 2019-12-12 19:25:23
问题 I have several dataSources I use for one UIViewController. My view controller uses KeyValue Observing in order to follow the state of certain properties at runtime. When I swap dataSources, I need to stop observing those properties. The problem is, I'm not sure of the class of the dataSource at runtime, therefor something like this is not valid: if (aDataSource != dataSource) { // Ensure we stop observing the existing dataSource, otherwise bad stuff can happen. [dataSource removeObserver:self