Re: NSArrayController Update Delay

2011-10-17 Thread Mike Abdullah

On 17 Oct 2011, at 22:22, Richard Somers wrote:

> SOLVED
> 
> On Oct 13, 2011, at 4:55 PM, Mike Abdullah wrote:
> 
>> I'm pretty sure the array controller is observing 
>> NSManagedObjectContextObjectsDidChangeNotification to arrange its objects. 
>> Normally, this doesn't fire until the end of the runloop. But you can force 
>> it to by calling -[NSManagedObjectContext processPendingChanges]
> 
> Calling processPendingChanges was the key to solving the controller update 
> delay issue. Thanks. Just curious how you came by this knowledge?

If it's not monitoring a relationship, the only public API for keeping an eye 
on changes is to observe that notification. The notification is documented not 
to fire immediately after a change, but to bunch up changes for efficiency.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSArrayController Update Delay

2011-10-17 Thread Richard Somers
SOLVED

On Oct 13, 2011, at 4:55 PM, Mike Abdullah wrote:

> I'm pretty sure the array controller is observing 
> NSManagedObjectContextObjectsDidChangeNotification to arrange its objects. 
> Normally, this doesn't fire until the end of the runloop. But you can force 
> it to by calling -[NSManagedObjectContext processPendingChanges]

Calling processPendingChanges was the key to solving the controller update 
delay issue. Thanks. Just curious how you came by this knowledge?

--Richard

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSArrayController Update Delay

2011-10-14 Thread William Squires
What about performSelector:withObject:afterDelay: with a delay of 0.0, I 
believe, will perform the selector after the current iteration of the run loop. 
Not sure about thread safety, though.

On Oct 13, 2011, at 10:17 PM, Steve Steinitz wrote:

> Hi Richard,
> 
> The advice you've received already is more sound than what I'm about to tell 
> you.  But my crude technique has solved the problem you mention and similar 
> problems.  
> 
> I wrote the following class method on a utility class into which I throw 
> stuff:
> 
> + (void)
> waitUntilEndOfNextRunLoop
> {
>   [[NSRunLoop mainRunLoop] runUntilDate:[NSDate distantPast]];  // finish 
> current iteration
>   [[NSRunLoop mainRunLoop] runUntilDate:[NSDate distantPast]];  // once 
> more so selection updates
> }
> 
> Whenever I have a problem like the one you mention, I invoke that method and 
> all is well.  I confess, I invoke it right and left.  I has no effect on 
> performance that I can notice.  But its far from pretty.
> 
> Cheers,
> 
> Steve
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/wsquires%40satx.rr.com
> 
> This email sent to wsqui...@satx.rr.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSArrayController Update Delay

2011-10-13 Thread Steve Steinitz
Hi Richard,

The advice you've received already is more sound than what I'm about to tell 
you.  But my crude technique has solved the problem you mention and similar 
problems.  

I wrote the following class method on a utility class into which I throw stuff:

+ (void)
waitUntilEndOfNextRunLoop
{
[[NSRunLoop mainRunLoop] runUntilDate:[NSDate distantPast]];  // finish 
current iteration
[[NSRunLoop mainRunLoop] runUntilDate:[NSDate distantPast]];  // once 
more so selection updates
}

Whenever I have a problem like the one you mention, I invoke that method and 
all is well.  I confess, I invoke it right and left.  I has no effect on 
performance that I can notice.  But its far from pretty.

Cheers,

Steve

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSArrayController Update Delay

2011-10-13 Thread Mike Abdullah

On 13 Oct 2011, at 21:20, Richard Somers wrote:

> Consider a NSArrayController in entity mode. When a managed object is 
> inserted into the managed object context the controller's arrangedObjects 
> property is not updated immediately.
> 
> Calling a controller 'fetch:' immediately after inserting the managed object 
> into the managed object context does not help. The controller's 
> arrangedObjects property is still not updated.
> 
> Perhaps there is a KVO change notification delay between the time when the 
> managed object is inserted into the managed object context and the time when 
> the controller finds out about the change.
> 
> Does anyone have any insight into what is going or how to force the 
> NSArrayController's arrangedObjects property to update?

I'm pretty sure the array controller is observing 
NSManagedObjectContextObjectsDidChangeNotification to arrange its objects. 
Normally, this doesn't fire until the end of the runloop. But you can force it 
to by calling -[NSManagedObjectContext processPendingChanges]

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSArrayController Update Delay

2011-10-13 Thread Richard Somers
On Oct 13, 2011, at 3:12 PM, Keary Suska wrote:

> How is this happening? Via code? or Via the NSArrayController (add: or 
> insert:)? In the latter case the docs say, "Beginning with Mac OS X v10.4 the 
> result of this method is deferred until the next iteration of the runloop so 
> that the error presentation mechanism can provide feedback as a sheet."

I have been inserting objects into the managed object context in code like this.

 [[NSManagedObject alloc] initWithEntity:entity 
insertIntoManagedObjectContext:moc];

Sometime later the array controller's arrangedObjects property will be 
automatically updated.

I have not been using NSArrayController's add: or insert: methods because at 
one time I was using them, in addition to 
initWithEntity:insertIntoManagedObjectContext:, and I was getting duplicate 
objects. Although I tried using both of them together just now (first 
initWithEntity:insertIntoManagedObjectContext: and then add:) and I am not 
getting any duplicates. So I am a little confused.

Is it normal practice to create a managed object with the designated 
initializer initWithEntity:insertIntoManagedObjectContext: and also insert the 
object into the controller using the controller's add: or insert: method?

--Richard

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSArrayController Update Delay

2011-10-13 Thread Keary Suska
On Oct 13, 2011, at 2:20 PM, Richard Somers wrote:

> Consider a NSArrayController in entity mode. When a managed object is 
> inserted into the managed object context the controller's arrangedObjects 
> property is not updated immediately.

How is this happening? Via code? or Via the NSArrayController (add: or 
insert:)? In the latter case the docs say, "Beginning with Mac OS X v10.4 the 
result of this method is deferred until the next iteration of the runloop so 
that the error presentation mechanism can provide feedback as a sheet."

> Calling a controller 'fetch:' immediately after inserting the managed object 
> into the managed object context does not help. The controller's 
> arrangedObjects property is still not updated.
> 
> Perhaps there is a KVO change notification delay between the time when the 
> managed object is inserted into the managed object context and the time when 
> the controller finds out about the change.

Not in my experience (except as noted above).

> Does anyone have any insight into what is going or how to force the 
> NSArrayController's arrangedObjects property to update?

If the action has been deferred as described above, you are mostly out of luck. 
You could chance manually turning the runloop but it is fragile and generally 
recommended against.

Best,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com