-1

I'm using StackMob with CoreData (remote Database), but I think this is a general Core Data question.

I have 3 entities:

  1. User (login)
  2. Cars
  3. Bikes

Each entity has several attributes.

A User can have multiple Cars and Bikes objects (to-many relationship). Cars and Bikes can only have one owner (User) (inverse to-one relationship).

Now lets say we have 2,000 Users. Each User is a car dealer and has 500 cars and 300 bikes records/objects stored in CoreData. I would like the User to fetch based on attributes of Cars and Bikes. I plan to use predicates for this. To cut back on constant fetch request, I also plan to use Cache.

However, the questions I have are:

  1. How should I save the record/object under each User? Is there a term for that in CoreData?

  2. I would like the User to login and be able fetch all the Cars/Bikes based on its attributes (Model, Manufacture, DateStamp, etc.) only within the objects the User created. I guess what I'm trying to avoid is when the User does a fetch request based on attributes in the Cars and Bikes entity, it only searches under its own User objects. I don't want the fetch request to search through all the others User's objects because that would be a waste as I'm afraid that'll slow down the app. What's the best way to set this up in CoreData?

Just went though 2 core data books and I'm not sure how to approach this. I know I'm not the brightest so I turn to the experts for some advice. Thank you.

user1107173
  • 10,334
  • 16
  • 72
  • 117
  • Is this application distributed per user? If so, you just keep a local object graph of cars and bikes for the specific user (how you fetch information from the server is another matter). – Dan Shelly Apr 05 '13 at 20:13
  • Thanks. User will need to eventually communicate with one and another i.e. to make offer on the Cars/Bikes and to check inventory. Can I still accomplish that with keeping a local object graph? Can you please elaborate? – user1107173 Apr 05 '13 at 20:20
  • Also what happens when a user gets a new device and logs in for the first time. How will he get the copy of the data? – user1107173 Apr 05 '13 at 20:24

1 Answers1

2

CoreData is actually really excelently optimized. What you need is an NSSearchPredicate and and NSFetchedResultsController. These are both kind of complicated and I can't just "tell" you how to use them. I found this open course to be EXTREMELY helpful

http://www.stanford.edu/class/cs193p/cgi-bin/drupal/

It builds a website fetching app in iOS using core data. Check the Core Data episode and if you don't know what he's talking about go back and watch some earlier ones

Pinwheeler
  • 1,061
  • 2
  • 13
  • 26