0

Let me just give you a quick rundown of my program for the end user: the user adds a credit card to the program, the program authorizes the card by sending information to the server, program displays "Approved" or "Denied" and the card is saved if approved.

Each card needs to have a unique identifier for other parts of the program to work, just like an array location +1 (i.e. first card = 1, second card = 2, etc.) but I'm unsure of how to implement this in Core Data unless it's already done somewhere and I just misunderstood the docs. So, how do I do this?

jscs
  • 63,694
  • 13
  • 151
  • 195
Baub
  • 5,004
  • 14
  • 56
  • 99
  • You can look here for a start - http://stackoverflow.com/questions/1351998/creating-a-unique-id-for-a-core-data-program-on-the-iphone. – Perception Jun 27 '11 at 18:05

1 Answers1

1

CoreData already provides this, assuming you store the Credit Card as it's own entity (makes it easy to refer to it from other objects. You can case you CreditCard managed object as an NSManagedObjectID, and presto, you have a thread safe identifier which represents that unique entity in it's data store.

Community
  • 1
  • 1
RyanR
  • 7,728
  • 1
  • 25
  • 39
  • I'd need more info from you to drill into more detail accurately. Since Core Data tracks references between objects automatically, I actually can't figure out why you would need this to refer to shared entities (like credit card). Just put a relationship on each kind of entity that needs a credit card reference, and make that relationship point to a Credit Card. Core Data handles referential integrity on it's own, you never have to see the ID. – RyanR Jun 27 '11 at 19:01
  • It's alright, I figured out how to add an ID by counting the number of objects in the entity and assigning it. I do need the ID to talk with the server that is created. Sorry I didn't provide more details, but thanks a lot for the help! – Baub Jun 27 '11 at 22:34