key-value-observing

Simply display the values of UIInterpolatingMotionEffect?

北慕城南 提交于 2019-12-11 03:45:45
问题 Here's a puzzle, imagine a typical UIInterpolatingMotionEffect ,,, UIInterpolatingMotionEffect *horizontalMotionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@" .. some property .." type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; horizontalMotionEffect.minimumRelativeValue = @(-50); horizontalMotionEffect.maximumRelativeValue = @(50); [someView addMotionEffect:horizontalMotionEffect]; Normally, you have to put in a property in line 3 there -- say, the center.x

Notifications causing no dealloc to be called

戏子无情 提交于 2019-12-11 03:38:01
问题 I am trying to use this within a project: https://github.com/zakkhoyt/VWWPermissionKit I do not understand KVO/Notification Center as much as I'd like so posting a question. Basically the init and dealloc for the Permission Manager look like this: - (instancetype)init { self = [super init]; if (self) { [[NSNotificationCenter defaultCenter] addObserverForName:VWWPermissionNotificationsPromptAction object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { dispatch_async

Trigger an event / method when UIWindow RootViewController changes SWIFT

删除回忆录丶 提交于 2019-12-11 01:56:43
问题 I'm working on an iOS framework. I have a requirement to log events when user enters or exits a particular View Controller. For that I was thinking if somehow I could be able to register a notification to trigger a custom method when the root view controller changes. Or perhaps use KVO. But I don't understand how to do this from an implementation point of view since I cannot find any such notification. Any help in this regard would be highly appreciated. Thanks. Please note that this is a

Observation info was leaked

与世无争的帅哥 提交于 2019-12-10 21:37:35
问题 I have a class and I'm using it as an observer of itself. I need it to notify me when other objects change its properties. When it gets deallocated I don't bother to remove the observer. However I get errors like this one: An instance 0xf819680 of class **** was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger.

How do i get the information from the observationInfo method in Objective C KVO?

不羁的心 提交于 2019-12-10 18:36:50
问题 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 the right direction please? EDIT In case any one misunderstand that im saying. My classes are already all KVO compliant. Now after you add the observer to a something object, self.something will now have binding information. If i did [self.something observationInfo], this returns a dictionary. I

Removing observers in post-ARC Cocoa

邮差的信 提交于 2019-12-10 17:44:04
问题 So far I have been removing observers (notifications or KVO) in the dealloc. Since dealloc is gone in ARC, what's the recommended way to do this? 回答1: -dealloc is not gone under ARC. The ivar-releasing and super-calling aspects are handled automatically, allowing you to omit it if that's all you were going to do, but you should still implement it for other things if it makes sense to do so. 来源: https://stackoverflow.com/questions/7827953/removing-observers-in-post-arc-cocoa

Objective-C KVO doesn't work with C unions

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 13:29:33
问题 I need to observe union-typed properties on an Objective-C class using KVO, but it seems I have no luck with this. I did some experiments: everything works fine as long as I am using a C struct. As soon as I replace the struct with a union, automatic KVO doesn't work anymore ( observeValueForKeyPath is not being called). Here's my small test class: AppDelegate.h: #import <Cocoa/Cocoa.h> typedef union { float data[3]; struct { float x,y,z; }; } vec3union; typedef struct { float x,y,z; }

Reading preferences set by UIAutomation's UIAApplication.setPreferencesValueForKey() on the target device?

佐手、 提交于 2019-12-09 21:56:02
问题 Over the last few days I've been playing with Apple's UIAutomation framework in an attempt to try to put together a suite of acceptance tests to drive the development of an app I'm working on (in a BDD type way...). One thing I'm bumping up against is how to get the SUT into a given state so I can begin my tests if I need to set some internal state for that to happen. The problem is that Apple's Javascript environment doesn't provide any functionality I could use to communicate with the

KVO notifications after mergeChangesFromContextDidSaveNotification

此生再无相见时 提交于 2019-12-09 15:12:38
问题 I'm using KVO to observe changes on a NSManagedObject. The NSManagedObject I'm observing is part of a NSManagedObject context that is on the main queue. When I update this object in a background (private queue concurrency type) context and then merge the saved changes to my main queue context (in mergeChangesFromContextDidSaveNotification), KVO notifications fire as expected. However, I expected that the notifications would only fire for key paths that actually changed and not for all

Cocoa key value observing a key/entry in a dictionary

淺唱寂寞╮ 提交于 2019-12-09 14:40:22
问题 Is it possible to observe a specific key in a dictionary? If so how can I do it? 回答1: Yes (although it only makes sense to be observing an NSMutableDictionary ). @interface Foo : NSObject @end @implementation Foo - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { NSLog(@"observing: -[%@ %@]", object, keyPath); NSLog(@"change: %@", change); } @end int main (int argc, const char * argv[]) { NSAutoreleasePool *pool = [