Re: Core Data : calling validation in awakeFromInsert problem ?
Re: Core Data : calling validation in awakeFromInsert problem ?
- Subject: Re: Core Data : calling validation in awakeFromInsert problem ?
- From: mmalcolm crawford <email@hidden>
- Date: Tue, 6 Sep 2005 17:36:44 -0700
On Sep 5, 2005, at 1:08 PM, Eric Morand wrote:
Well, that's simple : just like in iTunes, when you create two or
three playlist without renaming them, the playlist name is append
with "(index++). I need the same kind of behavior : in my app, user
can add managed objects via a "Add" button and I want the name of
the added object to "increase" automatically. Does it seem a bad
idea to you ?
No, not at all, the idea is good, it's the implementation that might
be sub-optimal.
How am I supposed to do if I want to be sure that a property is
unique for a given entity ?
The validation method is fine.
The way you generate the new names might be improved -- executing an
additional fetch for each collision is a (comparatively) huge
overheard. If you're creating small numbers (< 10) of unique names
like this, then you can probably get away with this, otherwise the
approach you take will depend on exactly the behaviour you want. If
all you want is for the name to be unique, then you might for example
create a new entity that stores just a number, and that represents
the current highest value. You just have to retrieve that. If the
user is forced to give a different name, then you might do something
similar just in memory without another entity. Worst case scenario
would be to use the same approach you have at the moment but fetch
all the current instances in one go and iterate through them in
memory...
mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden