Re: Core Data validateForUpdate

2009-12-21 Thread Matthew Lindfield Seager
On Tuesday, December 22, 2009, Gerriet M. Denkmann  wrote:
> What I ended up was: subclassing NSArrayController and overriding "newObject" 
> to return a new object prefilled with some some nice values, including 
> setting my uniqueKey to "undefined", "undefined_1", "undefined_2", etc.
> This will break of course if the user (out of sheer perversity) has already 
> created an "undefined_4".
Plus 1. I've done something similar in the past. My approach was to
see if "Untitled" was already taken, if so try "Untitled 2", etc. From
memory I kept going until 20 (a number all but the most perverse user
wouldn't reach in my case). If "Untitled 20" (& everything preceding)
was taken it got named with a date stamp, "Untitled 2009122215353803"
for example.

Regards,
Matt
___

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: Core Data validateForUpdate

2009-12-21 Thread Gerriet M. Denkmann

On 22 Dec 2009, at 04:50, Sean McBride wrote:

> On 12/20/09 3:19 PM, Gerriet M. Denkmann said:
> 
>> What I try to accomplish:
>> SomeEntity has a property called "uniqueKey" and this is (no big
>> surprise) meant to be unique.
>> 
>> When the "UniqueKey" column in my table view gets edited,
>> validateUniqueKey:error: gets called, I check the new value for
>> uniqueness and all is fine.
>> 
>> But hitting the "+" button several times inserts several objects with
>> the same key (Default Value).
> 
> As others have said, you probably want awakeFromInsert.
> 
> Depending what kind of 'unique' value you want, you could create a
> unique string like this:
> 
>   CFUUIDRef uuid = CFUUIDCreate (kCFAllocatorDefault);
>   if (uuid)
>   {
>   uuidStr = NSMakeCollectable (CFUUIDCreateString 
> (kCFAllocatorDefault,
> uuid));
>   CFRelease (uuid);
>   }
> 
> If you want/need to compare to other objects of the same entity type,
> then be warned that performing a fetch within awakeFromInsert is
> probably not a good idea.  NSArrayController doesn't like it when you do that.

Thanks for all your help and suggestions.

What I ended up was: subclassing NSArrayController and overriding "newObject" 
to return a new object prefilled with some some nice values, including setting 
my uniqueKey to "undefined", "undefined_1", "undefined_2", etc.
This will break of course if the user (out of sheer perversity) has already 
created an "undefined_4".

But as "real" entries never will look like "undefined_..." there is no problem 
with eliminating duplicating entities later.

And, as I said, editiing "undefined_..." into some "real" value will (via: 
Validates immediately) catch real duplicates.

Kind reagards,

Gerriet.

___

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: Core Data validateForUpdate

2009-12-21 Thread Sean McBride
On 12/20/09 3:19 PM, Gerriet M. Denkmann said:

>What I try to accomplish:
>SomeEntity has a property called "uniqueKey" and this is (no big
>surprise) meant to be unique.
>
>When the "UniqueKey" column in my table view gets edited,
>validateUniqueKey:error: gets called, I check the new value for
>uniqueness and all is fine.
>
>But hitting the "+" button several times inserts several objects with
>the same key (Default Value).

As others have said, you probably want awakeFromInsert.

Depending what kind of 'unique' value you want, you could create a
unique string like this:

CFUUIDRef uuid = CFUUIDCreate (kCFAllocatorDefault);
if (uuid)
{
uuidStr = NSMakeCollectable (CFUUIDCreateString 
(kCFAllocatorDefault,
uuid));
CFRelease (uuid);
}

If you want/need to compare to other objects of the same entity type,
then be warned that performing a fetch within awakeFromInsert is
probably not a good idea.  NSArrayController doesn't like it when you do that.

--

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com
Mac Software Developer  Montréal, Québec, Canada


___

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: Core Data validateForUpdate

2009-12-20 Thread Mark Townsend
I think that you want to implement the awakeFrom* methods on NSManagedObject
rather than the validate* methods for your purposes.

But as for them never getting called, make sure that your NSArrayController
bindings are correct.  Specifically that it's mapped to your NSManagedObject
subclass.  Also, check the method signature on your validate* methods.  Do
they return a BOOL and pass in a NSError ** for a parameter?

Cheers,
Mark

---
Mark Townsend
http://www.markltownsend.com


On Sun, Dec 20, 2009 at 4:00 AM, Mike Abdullah wrote:

> I think you misunderstand what -validateForInsert: and friends are for.
> They use "insert" here in the sense of inserting into the persistent store.
>
> So -validateForInsert: is called the first time the object is added to the
> store (calling -[NSManagedObjectContext save:] ). From then on,
> -validateForUpdate: will be called at each save that will modify the object.
> And finally, -validateForDelete: if removing from the store.
>
> On 20 Dec 2009, at 08:19, Gerriet M. Denkmann wrote:
>
> > I have a document based Core Data app.
> >
> > MyDocument.nib contains an NSTableView bound to an NSArrayController.
> > There also are "+" and "-" buttons, which send "add:" resp. "remove:" to
> the array controller.
> >
> > SomeEntity.m (subclass of NSManagedObject) implements validateForInsert:,
> validateForUpdate: and validateForDelete: - none of which are ever called.
> Why?
> >
> > What I try to accomplish:
> > SomeEntity has a property called "uniqueKey" and this is (no big
> surprise) meant to be unique.
> >
> > When the "UniqueKey" column in my table view gets edited,
> validateUniqueKey:error: gets called, I check the new value for uniqueness
> and all is fine.
> >
> > But hitting the "+" button several times inserts several objects with the
> same key (Default Value).
> >
> > What should I do? How to make validateForInsert: get called? 10.6.2.
> >
> >
> > Kind regards,
> >
> > Gerriet.
> >
> > ___
> >
> > 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/cocoadev%40mikeabdullah.net
> >
> > This email sent to cocoa...@mikeabdullah.net
>
> ___
>
> 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/mltownsend%40gmail.com
>
> This email sent to mltowns...@gmail.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: Core Data validateForUpdate

2009-12-20 Thread Mike Abdullah
I think you misunderstand what -validateForInsert: and friends are for. They 
use "insert" here in the sense of inserting into the persistent store.

So -validateForInsert: is called the first time the object is added to the 
store (calling -[NSManagedObjectContext save:] ). From then on, 
-validateForUpdate: will be called at each save that will modify the object. 
And finally, -validateForDelete: if removing from the store.

On 20 Dec 2009, at 08:19, Gerriet M. Denkmann wrote:

> I have a document based Core Data app.
> 
> MyDocument.nib contains an NSTableView bound to an NSArrayController.
> There also are "+" and "-" buttons, which send "add:" resp. "remove:" to the 
> array controller.
> 
> SomeEntity.m (subclass of NSManagedObject) implements validateForInsert:, 
> validateForUpdate: and validateForDelete: - none of which are ever called. 
> Why?
> 
> What I try to accomplish:
> SomeEntity has a property called "uniqueKey" and this is (no big surprise) 
> meant to be unique.
> 
> When the "UniqueKey" column in my table view gets edited, 
> validateUniqueKey:error: gets called, I check the new value for uniqueness 
> and all is fine.
> 
> But hitting the "+" button several times inserts several objects with the 
> same key (Default Value).
> 
> What should I do? How to make validateForInsert: get called? 10.6.2.
> 
> 
> Kind regards,
> 
> Gerriet.
> 
> ___
> 
> 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/cocoadev%40mikeabdullah.net
> 
> This email sent to cocoa...@mikeabdullah.net

___

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