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 ([email protected])

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 [email protected]

Reply via email to