Core Data Primary Key

Your options are: Use -[NSManagedObject objectID]. Note that this ID is temporary until either the object is saved for the first time or you call -[NSManagedObjectContext obtainPermanentIDsForObjects:error:] Use the CFUUID family of functions to generate a UUID for each object in your -awakeFromInsert method Create your own primary key-like system that stores an integer in … Read more

How to sync CoreData and a REST web service asynchronously and the same time properly propagate any REST errors into the UI

You should really take a look at RestKit (http://restkit.org) for this use case. It is designed to solve the problems of modeling and syncing remote JSON resources to a local Core Data backed cache. It supports an offline mode for working entirely from the cache when there is no network available. All syncing occurs on … Read more

Example or explanation of Core Data Migration with multiple passes?

I’ve figured out what Apple hints in their documentation. It’s actually very easy but a long way to go before it’s obvious. I’ll illustrate the explanation with an example. The initial situation is this: Data Model Version 1 It’s the model you get when you create a project with the “navigation based app with core … Read more

How to Deal with Temporary NSManagedObject instances?

NOTE: This answer is very old. See comments for full history. My recommendation has since changed and I no longer recommend using unassociated NSManagedObject instances. My current recommendation is to use temporary child NSManagedObjectContext instances. Original Answer The easiest way to do this is to create your NSManagedObject instances without an associated NSManagedObjectContext. NSEntityDescription *entity … Read more

Core Data background context best practice

This is an extremely confusing topic for people approaching Core Data for the first time. I don’t say this lightly, but with experience, I am confident in saying the Apple documentation is somewhat misleading on this matter (it is in fact consistent if you read it very carefully, but they don’t adequately illustrate why merging … Read more

What do I have to do to get Core Data to automatically migrate models?

I’ve now found out that this is quite simple – once you know where to look. In my AppDelegate I set-up the NSPersistentStoreCoordinator – and you need to add some options to this to tell it to handle auto-migrate: NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; NSError *error; _persistentStoreCoordinator = … Read more

Cannot create an NSPersistentStoreCoordinator with a nil model

I had exactly the same error message as the original post. I was wrestling with this for hours. It was this line in my AppDelegate.m. NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@”[same with name of xcdatamodeld]” withExtension:@”momd”]; For anyone out there searching this error message and finding this thread….try this first. You must make sure that … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)