Re: Using an auto incremented NSNumber as attribute in a NSManagedObject
Re: Using an auto incremented NSNumber as attribute in a NSManagedObject
- Subject: Re: Using an auto incremented NSNumber as attribute in a NSManagedObject
- From: Keary Suska <email@hidden>
- Date: Thu, 06 Mar 2008 14:48:16 -0700
- Thread-topic: Using an auto incremented NSNumber as attribute in a NSManagedObject
on 3/6/08 2:05 PM, email@hidden purportedly said:
> For example, when I create my first object, I want the numeric id
> field to be 1. Each subsequent insert should be the previous numeric
> id field + 1. I've read some of the posts regarding performing this
> and the general thought on this process is to create an additional
> entity in my data model containing the "current maximum index" then
> perform fetch, increment and get value of that field and use that for
> the incremented value of my new object. I'm not sure if this is still
> the only way or even the preferred way to perform this feat. I'm kind
> of worried about locking that "counter" field until the new managed
> object has been created to avoid any increment problems.
There aren't likely many solutions, as it boils down to the same
problem--the persistence of some sort of counter object. It makes the most
sense that this object would be part of the persistent store.
I suppose that on launch/open you could populate a custom object with the
next available index. May be faster than using an entity and fetching every
time.
Now, no matter what you do, you will run into the age old problem of
guaranteeing sequential numbering and/or no gap in sequence. And it's nearly
impossible to guarantee. In most RDBMS systems that have this feature, they
just say don't count on it.
So, if you had a thread-safe object (whether custom or NSManagedObject
subclass) with a property that increments and returns its incremented value
on every call, considering the above, the only locking you need is to make
it thread-safe. You will get the most performance and the least amount of
headaches.
> Additionally, I've tried accessing the docs located at the link below,
> but I keep getting connection errors, anyone else having problems
> accessing the documentation?
Good thing all reference docs are installed on your computer when you
install Xcode. Also, AppKiDo is indispensable.
Best,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden