Re: -[NSDocument fileURL] is observable (KVO). Documented?

2010-06-01 Thread Scott Anguish
Kyle gave the long answer. But, if it isn’t documented, don’t count on it (although there is some backfill required there). Also, being KVO compliant doesn’t necessarily mean you can simply bind to it, as you can’t be sure that the result will be returned on the main thread. KVO compliance

Re-establishing KVO in Managed objects after undo

2010-05-01 Thread Gideon King
Hi, I have some places in my code where I have managed objects that need to observe various key paths. If one of these objects has been deleted by the user, and then they undo, I need to re-establish the KVO. As undo doesn't call awakeFromFetch, I need to do this somewhere else. I have

Re: Re-establishing KVO in Managed objects after undo

2010-05-01 Thread Dave Fernandes
mechanisms other than KVO to keep your data model updated. KVO can be a world of hurt when used the way you are using it. There are old threads on this topic. See, for example, Strange NSManagedObjectContextObjectsDidChangeNotification behavior. Dave On 2010-05-01, at 9:42 AM, Gideon King wrote

Re: Re-establishing KVO in Managed objects after undo

2010-05-01 Thread Kyle Sluder
On Sat, May 1, 2010 at 9:34 AM, Dave Fernandes dave.fernan...@utoronto.ca wrote: If you are observing something that is not part of your data model, you might try using mechanisms other than KVO to keep your data model updated. KVO can be a world of hurt when used the way you are using

Re: Re-establishing KVO in Managed objects after undo

2010-05-01 Thread Gideon King
Thanks guys - will look into that. On 02/05/2010, at 3:11 AM, Kyle Sluder wrote: On Sat, May 1, 2010 at 9:34 AM, Dave Fernandes dave.fernan...@utoronto.ca wrote: If you are observing something that is not part of your data model, you might try using mechanisms other than KVO to keep your

Re: Re-establishing KVO in Managed objects after undo

2010-05-01 Thread Sean McBride
Gideon King (gid...@novamind.com) on 2010-05-01 09:42 said: Hi, I have some places in my code where I have managed objects that need to observe various key paths. Why? (I'm curious... I've never used such a pattern.) Perhaps instead you could override setters so that they perform other actions

Re: Re-establishing KVO in Managed objects after undo

2010-05-01 Thread Gideon King
It's inherited code from someone else, and am trying to work that out myself too...luckily there are only 5-6 of them, so I should be able to sort it out. Just looking at it now, I think a little refactoring should sort it out, and remove the need for KVO. On 02/05/2010, at 5:23 AM, Sean

Crash on NSKVOPendingNotificationRelease (KVO, bindings issue?)

2010-04-21 Thread Glen Low
I'm using KVO as a generalized recalculation engine, somewhat akin to how a spreadsheet recalcuates values based on what's changed. It's mostly successful once you eliminate cycles, but there is a persistent problem. On each relevant object, I have

Re: Crash on NSKVOPendingNotificationRelease (KVO, bindings issue?)

2010-04-21 Thread Quincey Morris
On Apr 21, 2010, at 17:47, Glen Low wrote: I'm using KVO as a generalized recalculation engine, somewhat akin to how a spreadsheet recalcuates values based on what's changed. It's mostly successful once you eliminate cycles, but there is a persistent problem. The likely answer (see below

CGPoint and KVO

2010-04-03 Thread Roland King
much in the KVO documentation about CGPoint or how I should expect to receive structs or other primitives. This is iPhone OS (incase that makes a difference). ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests

Re: CGPoint and KVO

2010-04-03 Thread Kiel Gillard
getValue:oldPoint ] Is this correct? I've failed to find anything much in the KVO documentation about CGPoint or how I should expect to receive structs or other primitives. In the case of NSPoint/CGPoint: CGPoint oldPoint = [oldValue pointValue]; This is iPhone OS (incase that makes a difference

Re: CGPoint and KVO

2010-04-03 Thread Roland King
] Is this correct? I've failed to find anything much in the KVO documentation about CGPoint or how I should expect to receive structs or other primitives. In the case of NSPoint/CGPoint: CGPoint oldPoint = [oldValue pointValue]; This is iPhone OS (incase that makes a difference

Re: CGPoint and KVO

2010-04-03 Thread Clark S. Cox III
the CGPoint from it CGPoint oldPoint; id oldValue = [ change valueForKey:NSKeyValueChangeOld ]; [ (NSValue*)oldValue getValue:oldPoint ] Is this correct? I've failed to find anything much in the KVO documentation about CGPoint or how I should expect to receive structs

KVO on NSDictionary elements

2010-03-11 Thread Gustavo Pizano
Hello all. Im implementing a live filter, and each, time I insert a filter in the filterDictionary the controller (which is another class) gets notified about the insertion.\ I was reading the KVO, and its says something about NSKeyValueChangeKindKey. So this is what Im doing in the Controller

Re: KVO and object release timing (for a NSCollectionView)

2010-01-23 Thread vincent habchi
, it is always best to post the crash report. Well, I wrote a workaround, so I can't give you a crash report anymore. The crash happens in the KVO unregistering routine. The problem is that when the represented object is removed from the array controller, the corresponding NSView is not immediately

Re: KVO and object release timing (for a NSCollectionView)

2010-01-23 Thread Kyle Sluder
the NSView slowly fade away. Net result is that the NSView survives some tenths of a second after the represented object is released, and the KVO unregistering crashes. Hooray for retain cycles; if you avoid them you get overrelease bugs! (I can't wait for garbage collection.) This happens a lot

KVO and object release timing (for a NSCollectionView)

2010-01-22 Thread vincent habchi
is linked to a NSCollectionView. The NSView I use to visually represent the NSArrayController contents includes a slider that observes a parameter of C (more specifically, opacity) through KVO. So far, so good. I have a NSButton in C to remove from the array controller the A object it represents

Re: KVO and object release timing (for a NSCollectionView)

2010-01-22 Thread Corbin Dunn
On Jan 22, 2010, at 7:01 AM, vincent habchi wrote: I have a NSButton in C to remove from the array controller the A object it represents. However, each time I click on that button, I first get a warning telling me that I remove an observed object before releasing the observer, and then

Re: How to know whether property in Cocoa class is KVO-compliant?

2010-01-11 Thread Scott Anguish
On Jan 10, 2010, at 11:18 PM, Dave Fernandes wrote: Look for Cocoa Bindings Guide in the docs. It would be nice if it were cross-referenced in every class description. Please file a bug about that. Class methods that are KVO compatible are stated as such in the reference. They aren’t

Re: How to know whether property in Cocoa class is KVO-compliant?

2010-01-11 Thread Quincey Morris
On Jan 10, 2010, at 19:58, Jerry Krinock wrote: After studying some about bindings during the last week, I decided that, just for fun, I would bind an NSSegmentedControl to its window controller using a binding instead of target/action. I thought that selectedSegment might be a KVO

Re: Bindings; Was: whether property in Cocoa class is KVO-compliant?

2010-01-11 Thread Jerry Krinock
that change data flows in the *opposite* direction of the *to*. That is, if I bind myself *to* you, I observe what you do and your changes flow back *to* me. I wonder why bindings was not as an extension of KVO, instead of as a separate sideshow. The effect is the same as KVO

Re: Bindings; Was: whether property in Cocoa class is KVO-compliant?

2010-01-11 Thread Mike Abdullah
. Now I know that a binding is only one way, and further that change data flows in the *opposite* direction of the *to*. That is, if I bind myself *to* you, I observe what you do and your changes flow back *to* me. I wonder why bindings was not as an extension of KVO, instead

Re: Bindings; Was: whether property in Cocoa class is KVO-compliant?

2010-01-11 Thread Jerry Krinock
On 2010 Jan 11, at 09:46, Mike Abdullah wrote: I wonder why bindings was not as an extension of KVO, instead of as a separate sideshow. The effect is the same as KVO, with the addition that a designated setter is automatically invoked in the observer when a change is observed. What

Re: Bindings; Was: whether property in Cocoa class is KVO-compliant?

2010-01-11 Thread mmalc Crawford
On Jan 11, 2010, at 9:01 am, Jerry Krinock wrote: I wonder why bindings was not as an extension of KVO, instead of as a separate sideshow. The effect is the same as KVO, It's not at all. Bindings uses KVO to ensure that things are kept synchronised; KVO is a general mechanism that allows

Re: Bindings; Was: whether property in Cocoa class is KVO-compliant?

2010-01-11 Thread Quincey Morris
On Jan 11, 2010, at 10:04, Jerry Krinock wrote: Well, I guess I'm talking about the default implementation then. I just mean I'd probably have an easier time learning bindings if they were called maybe KVO Plus, and somehow used a class' regular properties on both ends of a binding

How to know whether property in Cocoa class is KVO-compliant?

2010-01-10 Thread Jerry Krinock
After studying some about bindings during the last week, I decided that, just for fun, I would bind an NSSegmentedControl to its window controller using a binding instead of target/action. I thought that selectedSegment might be a KVO-compliant property of NSSegmentedControl because it has

Re: How to know whether property in Cocoa class is KVO-compliant?

2010-01-10 Thread Dave Fernandes
bindings during the last week, I decided that, just for fun, I would bind an NSSegmentedControl to its window controller using a binding instead of target/action. I thought that selectedSegment might be a KVO-compliant property of NSSegmentedControl because it has a -selectedSegment

Re: How to know whether property in Cocoa class is KVO-compliant?

2010-01-10 Thread mmalc Crawford
doesn't catalogue KVO compliance, it lists bindings. In general, controller objects observe model objects, and views observe controllers and models -- you typically don't bind to views. Thus you shouldn't generally expect views' properties to be observable. mmalc

Screwy Binding/KVO

2009-12-11 Thread Steven Degutis
Hi, Sorry if this has been posted before; I did a quick scour but might not have used the right keywords (this issue isn't very general). Basically I'm noticing that when I expect KVO observations to be triggered, they aren't. Most likely this is due to my misunderstanding, but I'd like to post

Re: Screwy Binding/KVO

2009-12-11 Thread Quincey Morris
On Dec 11, 2009, at 09:10, Steven Degutis wrote: [reformatted to be less annoying] // when this is called, the KVO in SDObject is triggered with an empty array [object bind:@content toObject:controller2 withKeyPath:@arrangedObjects options:nil]; NSLog(@mark 2); Yeah, well, at this point

Re: Big memory/time consumption in NSTreeController KVO GC

2009-12-09 Thread Benjamin Rister
On Dec 8, 2009, at 4:35 PM, Greg Parker wrote: Which OS version is this? 10.6.2 fixed a performance problem with garbage collection and large KVO populations. If you still have trouble in 10.6.2+ then you should file a bug report. On Dec 8, 2009, at 6:38 PM, Rob Keniger wrote: Please see

Re: Big memory/time consumption in NSTreeController KVO GC

2009-12-09 Thread jonat...@mugginsoft.com
to spend far too much time fighting with NSTreeController/NSArrayController trying to get real world reliable performance out of them. I think the bindings + KVO technology is great but with GC, at least, it seems easy to contrive a demon. 10.6 especially seems rather toxic. Maybe it's time to back off

Big memory/time consumption in NSTreeController KVO GC

2009-12-08 Thread Benjamin Rister
in the auto zone. The only references to some of these key function names I could find on the web were in the libauto sources, and no mention at all in mailing lists, so it doesn’t seem like anybody else has posted about this before. Any ideas about why NSTreeController’s KVO is taking up so much memory

Re: Big memory/time consumption in NSTreeController KVO GC

2009-12-08 Thread jonat...@mugginsoft.com
Any ideas about why NSTreeController’s KVO is taking up so much memory/CPU with bookkeeping? Any suggestions for working around the problem? I assume that you are using bindings. Looks like a typical KVO notification storm to me. What works well for adding and updating one or two

Re: Big memory/time consumption in NSTreeController KVO GC

2009-12-08 Thread Benjamin Rister
On Dec 8, 2009, at 2:44 PM, jonat...@mugginsoft.com wrote: Any ideas about why NSTreeController’s KVO is taking up so much memory/CPU with bookkeeping? Any suggestions for working around the problem? I assume that you are using bindings. Yes. Looks like a typical KVO notification storm

Re: Big memory/time consumption in NSTreeController KVO GC

2009-12-08 Thread Greg Parker
, it’s happening after all of the actual, real work is done. Which OS version is this? 10.6.2 fixed a performance problem with garbage collection and large KVO populations. If you still have trouble in 10.6.2+ then you should file a bug report. -- Greg Parker gpar...@apple.com Runtime

Re: Big memory/time consumption in NSTreeController KVO GC

2009-12-08 Thread Rob Keniger
On 09/12/2009, at 7:35 AM, Greg Parker wrote: Which OS version is this? 10.6.2 fixed a performance problem with garbage collection and large KVO populations. If you still have trouble in 10.6.2+ then you should file a bug report. There are still massive remaining performance issues

Re: firstResponder KVO snow leopard crash; bug?

2009-11-19 Thread Corbin Dunn
On Nov 18, 2009, at 5:06 PM, Sean McBride wrote: On 11/18/09 9:00 AM, Corbin Dunn said: Oh -- another thing. Does your subclass of NSCollectionView override: (void)viewWillMoveToWindow:(NSWindow *)window { but not call super? If not... call super! Your classes should always call super

Re: firstResponder KVO snow leopard crash; bug?

2009-11-19 Thread Corbin Dunn
0x1ab6ad40: Observer: 0x19427a80, Key path: firstResponder, Options: New: YES, Old: NO, Prior: NO Context: 0x0, Property: 0x4453e60 ) I looked at what the observer object's class is, and it's a subclass of NSCollectionView. We do not explicitly setup a KVO relationship for firstResponder. I

Re: firstResponder KVO snow leopard crash; bug?

2009-11-18 Thread Keary Suska
On Nov 17, 2009, at 2:04 PM, Aaron Clarke wrote: Even if it doesn't crash, closing the NSWindow always results in the following error message. An instance 0x11b75230 of class MyWindow was deallocated while key value observers were still registered with it. Observation info was leaked, and

Re: firstResponder KVO snow leopard crash; bug?

2009-11-18 Thread Corbin Dunn
: 0x0, Property: 0x4453e60 ) I looked at what the observer object's class is, and it's a subclass of NSCollectionView. We do not explicitly setup a KVO relationship for firstResponder. I also noticed that the Application Kit Release Notes for Snow Leopard mention that firstResponder is KVO

Re: firstResponder KVO snow leopard crash; bug?

2009-11-18 Thread Corbin Dunn
: 0x0, Property: 0x4453e60 ) I looked at what the observer object's class is, and it's a subclass of NSCollectionView. We do not explicitly setup a KVO relationship for firstResponder. I also noticed that the Application Kit Release Notes for Snow Leopard mention that firstResponder is KVO

Re: firstResponder KVO snow leopard crash; bug?

2009-11-18 Thread Sean McBride
On 11/18/09 9:00 AM, Corbin Dunn said: Oh -- another thing. Does your subclass of NSCollectionView override: (void)viewWillMoveToWindow:(NSWindow *)window { but not call super? If not... call super! Your classes should always call super if it is defined in a superclass, unless you have a good

Re: firstResponder KVO snow leopard crash; bug?

2009-11-18 Thread Aaron Clarke
, Old: NO, Prior: NO Context: 0x0, Property: 0x4453e60 ) I looked at what the observer object's class is, and it's a subclass of NSCollectionView. We do not explicitly setup a KVO relationship for firstResponder. I also noticed that the Application Kit Release Notes for Snow Leopard mention

Re: firstResponder KVO snow leopard crash; bug?

2009-11-18 Thread Sean McBride
Aaron Clarke (clark...@gmail.com) on 2009-11-18 8:28 PM said: Oh -- another thing. Does your subclass of NSCollectionView override: (void)viewWillMoveToWindow:(NSWindow *)window { but not call super? If not... call super! Your classes should always call super if it is defined in a

firstResponder KVO snow leopard crash; bug?

2009-11-17 Thread Aaron Clarke
a subclass of NSCollectionView. We do not explicitly setup a KVO relationship for firstResponder. I also noticed that the Application Kit Release Notes for Snow Leopard mention that firstResponder is KVO-compliant, which makes me believe this is something new in Snow Leopard. All

KVO cross dependencies

2009-11-13 Thread Half Activist
Hi all, I have sevral objects of different kind that observe values on each other. Now, when the objects are being released, I get an exception from the KVO stuff telling me that an object is being deallocated while still observed. And that's justified. Yet, the problem is in whatever

Re: KVO cross dependencies

2009-11-13 Thread Roland King
: Hi all, I have sevral objects of different kind that observe values on each other. Now, when the objects are being released, I get an exception from the KVO stuff telling me that an object is being deallocated while still observed. And that's justified. Yet, the problem

Programmatic Binding KVC KVO

2009-11-04 Thread Richard Somers
I have a managed object context with two attached NSObjectControllers in entity mode. Both controllers control the same entity. managed object model nib 1 controller user interface bind in interface builder nib 2 controller user interface (custom view)

Re: Programmatic Binding KVC KVO

2009-11-04 Thread Kyle Sluder
On Nov 4, 2009, at 6:04 AM, Richard Somers rsomers.li...@infowest.com wrote: I have a managed object context with two attached NSObjectControllers in entity mode. Both controllers control the same entity. Important: do you really mean entity, or do you mean managed object? managed

Re: Programmatic Binding KVC KVO

2009-11-04 Thread Richard Somers
On Nov 4, 2009, at 9:40 AM, Kyle Sluder wrote: Nib 2 only partly works. Changes made in the custom view do not show up in the managed object model or in the user interface found in nib 1. So now we also need to see your custom view code. Here is the code for nib 2 which only partly

Re: Programmatic Binding KVC KVO

2009-11-04 Thread Kyle Sluder
before, the default NSObject bindings implementation only set up KVO in one direction. If you call -[myView bind:@num toObject:myController withKeyPath:@someModelKeyPath options:0], KVO will only occur from [myController].someModelKeyPath -- [myView].num. NSObject doesn't (and can't) also set up

Re: Programmatic Binding KVC KVO

2009-11-04 Thread Jim Correia
On Nov 4, 2009, at 3:17 PM, Richard Somers wrote: @interface MyView : NSView { double num; } @end @implementation MyView - (double)num { return num; } - (void)setnum:(double)newNum { [self willChangeValueForKey:@num]; num = newNum; [self didChangeValueForKey:@num]; }

Re: Programmatic Binding KVC KVO

2009-11-04 Thread Richard Somers
On Nov 4, 2009, at 2:31 PM, Kyle Sluder wrote: This invokes the default implementation of - bind:toObject:withKeyPath:options:, which takes care of the model - view communication. You now need to take care of the view - model communication. As described in the User Updates a Value in the

Re: Programmatic Binding KVC KVO

2009-11-04 Thread Rob Keniger
On 05/11/2009, at 8:42 AM, Richard Somers wrote: See mmalc’s Graphics Bindings sample: http://homepage.mac.com/mmalc/CocoaExamples/controllers.html Sometimes Cocoa can be overwhelming. This will help. Thank you so much. :) You might also find this blog post very helpful:

Re: Programmatic Binding KVC KVO

2009-11-04 Thread mmalc Crawford
On Nov 4, 2009, at 5:20 pm, Rob Keniger wrote: See mmalc’s Graphics Bindings sample: http://homepage.mac.com/mmalc/CocoaExamples/controllers.html Sometimes Cocoa can be overwhelming. This will help. Thank you so much. :) You might also find this blog post very helpful:

Re: Core Data design question: receiving KVO notifications of partially mutated objects

2009-11-03 Thread Sean McBride
On 11/2/09 12:58 PM, Ben Trumbull said: This doesn't really have anything to do with Core Data. However, for NSManagedObject, Core Data already provides the change coalescing and NSNotifications for you. You can respond within NSManagedObjectContextObjectsDidChangeNotification instead. So I

re: Core Data design question: receiving KVO notifications of partially mutated objects

2009-11-02 Thread Ben Trumbull
What is considered best practice when it comes to mutating many properties of a managed object, specifically with regard to KVO observers getting notified before all mutations are finished? This is a problem intrinsic to the design of KVO. KVO is all about fine grained per property

Re: Core Data design question: receiving KVO notifications of partially mutated objects

2009-11-02 Thread Sean McBride
to an invalid intermediate state is a more reasonable problem to consider, but it normally shouldn't matter either. Normally KVO will be used to update your UI and/or maintain undo. You mention Core Data so that will handle undo for you but even if you were doing that yourself it shouldn't matter. Undo

Re: Core Data design question: receiving KVO notifications of partially mutated objects

2009-11-02 Thread Sean McBride
On 11/2/09 12:58 PM, Ben Trumbull said: What is considered best practice when it comes to mutating many properties of a managed object, specifically with regard to KVO observers getting notified before all mutations are finished? This is a problem intrinsic to the design of KVO. KVO is all

Re: Core Data design question: receiving KVO notifications of partially mutated objects

2009-11-02 Thread Ben Trumbull
If your issue is that drawing or recalculation is occurring too frequently after KVO changes, you can consider coalescing and deferring the observers' actions instead of performing them synchronously. This can be valuable even for less complex KVO issues. You could also refactor the 3

Core Data design question: receiving KVO notifications of partially mutated objects

2009-10-30 Thread Sean McBride
Hi all, What is considered best practice when it comes to mutating many properties of a managed object, specifically with regard to KVO observers getting notified before all mutations are finished? Let's say I have an Rectangle object. It has properties: colour, width, height. Imagine some

Re: Core Data design question: receiving KVO notifications of partially mutated objects

2009-10-30 Thread Kiel Gillard
On 31/10/2009, at 9:01 AM, Sean McBride wrote: Hi all, What is considered best practice when it comes to mutating many properties of a managed object, specifically with regard to KVO observers getting notified before all mutations are finished? In situations like these I personally tend

Re: Core Data design question: receiving KVO notifications of partially mutated objects

2009-10-30 Thread Graham Cox
problem to consider, but it normally shouldn't matter either. Normally KVO will be used to update your UI and/or maintain undo. You mention Core Data so that will handle undo for you but even if you were doing that yourself it shouldn't matter. Undo will record each property change and group

Re: Core Data KVO with To-Many Relationships

2009-10-08 Thread Ben Trumbull
. KVO doesn't have an easy way to observe a collection's contents, so the NSNotification approach is your best bet. - (void)awakeFromFetch { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(managedObjectContextDidChange:) name

Core Data KVO with To-Many Relationships

2009-10-07 Thread John McIntosh
Hi all. I am working on a Core Data application which contains an entity that needs to be notified of changes in entities that it has a relationship to. Let's talk about this in terms of Apple's example with Departments and Employees. As described here

KVC, KVO and dot notation. Was: whether to use core data...

2009-10-03 Thread Colin Howarth
On 3 Oct, 2009, at 23:51, Klaus Backert wrote: On 3 Oct 2009, at 22:06, Colin Howarth wrote: If you use dot notation and properties, you are using the -value and -setValue: accessor methods, which is KVC compliant and means that KVO bits will get notified, no? No. From the documentation

Re: KVO can be unsafe in -init?

2009-09-13 Thread Uli Kusterer
Am 09.09.2009 um 11:02 schrieb John Chang: No, it's a singleton. Basically it's a manager object that wants to continually monitor something else for changes. Also, - addObserver is the last line of code in -init, before the return. This article may be of interest to you:

Re: KVO can be unsafe in -init?

2009-09-13 Thread John Chang
with the NSKeyValueObservingOptionInitial option, which causes KVO to make a bunch of calls to user code (with potentially lots of side effects) directly inside -addObserver:etc:etc:. So the afterDelay: idea wouldn't really help, since in both cases -addObserver: is going to be catching and rethrowing exceptions. (One of our

Re: KVO can be unsafe in -init?

2009-09-12 Thread Jerry Krinock
On 2009 Sep 11, at 05:55, John Chang wrote: Just to update you guys. We managed to reproduce the problem in- house and catch it in the debugger. I'd be interested to know how John is going to fix this problem. I myself have used the performSelector:withObject:afterDelay:0.0 solution in

Re: KVO can be unsafe in -init?

2009-09-11 Thread John Chang
0x00a258de in -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] () The ah-ha is that KVO is catching and re-throwing exceptions in -addObserver:.. If one sets a breakpoint in the code that gets called indirectly, you'll get something much more interesting

Re: KVO can be unsafe in -init?

2009-09-09 Thread Ben Trumbull
On 08/09/2009, at 12:36 AM, John Chang wrote: Hi all, Question: is it unsafe for some reason to be adding yourself as a KVO observer during -init? We have a singleton with an -init that looks something like this: - (id)init { if ((self = [super init])) { _foo = [[NSMutableDictionary alloc

Re: KVO can be unsafe in -init?

2009-09-09 Thread John Chang
the observer is causing this exception? There's nothing KVO related in this message. Sorry, I was thinking of including the backtrace and I guess I didn't. In -init, -addObserver: is only called once, so we're pretty certain about the exact line of code that is being indicated here, unless

Re: KVO can be unsafe in -init?

2009-09-09 Thread John Chang
On 9 sep 2009, at 11.21, Mike Abdullah wrote: Well I would question why you're calling +[XYZManager sharedManager] from within -[XYZManager init] like that. What if you change your init routine to: Oops, sorry. It's actually two different classes which I renamed incorrectly for the

Re: KVO can be unsafe in -init?

2009-09-09 Thread Mike Abdullah
On 9 Sep 2009, at 10:31, John Chang wrote: On 9 sep 2009, at 11.21, Mike Abdullah wrote: Well I would question why you're calling +[XYZManager sharedManager] from within -[XYZManager init] like that. What if you change your init routine to: Oops, sorry. It's actually two different

Re: KVO can be unsafe in -init?

2009-09-09 Thread Roland King
a system-generated class which has its own KVO setup, or you subclass something you wrote last year and something which relies on KVO stops working and you've often torn half your code apart before you find it. What do I use. Normally a class static, provided that's granular enough

Re: KVO can be unsafe in -init?

2009-09-09 Thread Dave Keck
() method (taking care again to check I'm not being called for a subclass) and stuff into a static I kept for the purpose. Personally, for my KVO contexts, I use: static void *const MyClass_KVOContext = (void *)MyClass_KVOContext; I've never seen anyone else use it, but I find

Re: KVO can be unsafe in -init?

2009-09-09 Thread Keith Duncan
On 9 Sep 2009, at 11:21, Dave Keck wrote: static void *const MyClass_KVOContext = (void *)MyClass_KVOContext; That certainly is unusual, I use the following macro: #define NSSTRING_CONTEXT(var) static NSString *var = @#var then use the address of the identifier passed as var. This has the

Re: KVO can be unsafe in -init?

2009-09-09 Thread Marc Respass
We have a singleton with an -init that looks something like this: - (id)init { if ((self = [super init])) { _foo = [[NSMutableDictionary alloc] init]; _bar = [[NSMutableDictionary alloc] init]; [[XYZManager sharedManager] addObserver:self forKeyPath:@allObjects

Re: KVO can be unsafe in -init?

2009-09-09 Thread Roland King
What about writing a method, -finishSetup, and invoke it with a delay like below? I use this pattern a lot with loading views. It seems like it would work so that you add observation when your object is ready. Marc [self performSelectorOnMainThread:@selector(finishSetup)

Re: KVO on Distributed Objects with exception handling.

2009-09-08 Thread Edward Chan
I've just tested it on Snow Leopard (10a380), and it works as expected. Do you happen to remember the technical reasons why KVO on DOs would fail? Ed On Mon, Sep 7, 2009 at 11:55 PM, Scott Anguishsc...@cocoadoc.com wrote: In spite of the fact that it might be working, it isn't supported

Re: KVO on Distributed Objects with exception handling.

2009-09-08 Thread Scott Anguish
On Sep 8, 2009, at 10:38 AM, Edward Chan wrote: I've just tested it on Snow Leopard (10a380), and it works as expected. Perhaps. But as I said, unsupported, untested internally, and could break at any time. Do you happen to remember the technical reasons why KVO on DOs would fail

KVO can be unsafe in -init?

2009-09-08 Thread John Chang
Hi all, Question: is it unsafe for some reason to be adding yourself as a KVO observer during -init? We have a singleton with an -init that looks something like this: - (id)init { if ((self = [super init])) { _foo = [[NSMutableDictionary alloc] init]; _bar = [[NSMutableDictionary alloc] init

Re: KVO on Distributed Objects with exception handling.

2009-09-08 Thread Graham Lee
On Sep 7, 2009, at 21:45 , Edward Chan wrote: Great... How long ago did you ask the Apple engineers? I haven't tried this piece of code with Snow Leopard actually... This was back in February, I was probably testing on Leopard. The difference between what you and I tried was that I used -

Re: KVO on Distributed Objects with exception handling.

2009-09-08 Thread Graham Lee
On Sep 7, 2009, at 20:02 , Edward Chan wrote: Hello, I'm using KVO on a Distributed Object, and I am binding my UI controls based on the observer. Hi, not much of constructive help from me I'm afraid, just a warning. I also did the same thing once, and the reaction from Apple engineers

Re: KVO can be unsafe in -init?

2009-09-08 Thread Roland King
John Chang wrote: Hi all, Question: is it unsafe for some reason to be adding yourself as a KVO observer during -init? We have a singleton with an -init that looks something like this: - (id)init { if ((self = [super init])) { _foo = [[NSMutableDictionary alloc] init]; _bar

Re: KVO can be unsafe in -init?

2009-09-08 Thread Stephen J. Butler
exception 'NSInvalidArgumentException', reason: '*** -[NSCFDictionary setObject:forKey:]: attempt to insert nil key' Why do you think registering the observer is causing this exception? There's nothing KVO related in this message. ___ Cocoa-dev mailing

Re: KVO can be unsafe in -init?

2009-09-08 Thread Graham Cox
On 08/09/2009, at 12:36 AM, John Chang wrote: Hi all, Question: is it unsafe for some reason to be adding yourself as a KVO observer during -init? We have a singleton with an -init that looks something like this: - (id)init { if ((self = [super init])) { _foo = [[NSMutableDictionary alloc

Re: KVO can be unsafe in -init?

2009-09-08 Thread Ken Ferry
? If so, -observeValueForKeyPath: is getting called on them before they've done their work in init. -Ken On Mon, Sep 7, 2009 at 7:36 AM, John Chang john.r.ch...@gmail.com wrote: Hi all, Question: is it unsafe for some reason to be adding yourself as a KVO observer during -init? We have

KVO on Distributed Objects with exception handling.

2009-09-07 Thread Edward Chan
Hello, I'm using KVO on a Distributed Object, and I am binding my UI controls based on the observer. For example: MonkeyViewController.isEatingABanana - Binded to a UI checkbox. MonkeyViewController.m: @propery (readwrite, assign) BOOL isEatingABanana; -(id)init { ... [MonkeyBrainDOObject

Re: KVO on Distributed Objects with exception handling.

2009-09-07 Thread Edward Chan
Great... How long ago did you ask the Apple engineers? I haven't tried this piece of code with Snow Leopard actually... On Mon, Sep 7, 2009 at 3:29 PM, Graham Leel...@thaesofereode.info wrote: On Sep 7, 2009, at 20:02 , Edward Chan wrote: Hello, I'm using KVO on a Distributed Object, and I

Re: KVO on Distributed Objects with exception handling.

2009-09-07 Thread Edward Chan
, Graham Leel...@thaesofereode.info wrote: On Sep 7, 2009, at 20:02 , Edward Chan wrote: Hello, I'm using KVO on a Distributed Object, and I am binding my UI controls based on the observer. Hi, not much of constructive help from me I'm afraid, just a warning. I also did the same thing

Re: KVO on Distributed Objects with exception handling.

2009-09-07 Thread Scott Anguish
In spite of the fact that it might be working, it isn't supported. When I talked to engineering about this, this is what I was told. He was a bit shocked it worked at all, and it isn't tested as part of releases. On Sep 7, 2009, at 3:02 PM, Edward Chan wrote: Hello, I'm using KVO

Re: KVO on Distributed Objects with exception handling.

2009-09-07 Thread Scott Anguish
On Sep 7, 2009, at 4:45 PM, Edward Chan wrote: Great... How long ago did you ask the Apple engineers? I haven't tried this piece of code with Snow Leopard actually... It still isn't supported in SL. I'd be shocked if it ever is. ___ Cocoa-dev

Re: Changes in KVO behavior on SL?

2009-09-02 Thread Kevin Brock
: yourself, nor construct change dictionaries. When a property changes in a way that KVO can't automatically track, you are supposed to call -will/ didChangeValueForKey: (or the corresponding will/didChange... methods for set or array mutation) and KVO will generate the change notification

Re: Changes in KVO behavior on SL?

2009-09-02 Thread Derek Chesterfield
on the information in the change dictionary. If you were using will/ didChange..., then KVO can be expected to invoke valueForKey: on the object whose property is changing, but that's not what (you say) you're doing. Thanks. That was helpful. On 10.5 the receiver *does* apparently

Changes in KVO behavior on SL?

2009-09-01 Thread Kevin Brock
We've got an app that is using keyValueForPath: and observeValueForKeyPath:ofObject:change:context: to keep a status window up-to-date. On 10.5 it works fine. On 10.6 keyValueForPath: is called exactly once per property. When we later create a change dictionary and send

Re: Changes in KVO behavior on SL?

2009-09-01 Thread Kyle Sluder
On Tue, Sep 1, 2009 at 5:14 PM, Kevin Brockap...@kevin.com wrote: We've got an app that is using keyValueForPath: and observeValueForKeyPath:ofObject:change:context: to keep a status window up-to-date. It's valueForKeyPath:. On 10.5 it works fine.  On 10.6 keyValueForPath: is called exactly

KVO: when to stop observing?

2009-08-30 Thread Michel Schinz
Hi, In my program, I rely heavily on key-value observing (KVO), which I find really useful. However, I haven't found a good way to know when I should stop observing, i.e. call removeObserver:forKeyPath:. Until now, my solution has been to start observing in the designated initialiser

Re: KVO: when to stop observing?

2009-08-30 Thread Steven Degutis
If you're targeting 10.6 only, this is taken care of you automatically according to the Foundation release notes. Any KVO observers will be automagically removed as observers by the runtime, and thus you won't have to do it at all. The release notes hint that the appropriate solution for 10.5

<    1   2   3   4   5   6   7   >