Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between the 5 Magical Record setup methods?

Can anyone give a description of each of the 5 setup methods?

(void) setupCoreDataStack;
(void) setupAutoMigratingDefaultCoreDataStack;
(void) setupCoreDataStackWithInMemoryStore;
(void) setupCoreDataStackWithStoreNamed:(NSString *)storeName;
(void) setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(NSString *)storeName;

What do they each do and what is the use case for each?

like image 521
zakdances Avatar asked Nov 15 '12 03:11

zakdances


1 Answers

setupCoreDataStack

Use this when you're just getting started with MagicalRecord. This will, as the method states, set up your default Core Data stack. The pieces of the stack are well know and comprise of: NSPersistentStore, NSPersistentStoreCoordinate, NSManagedObjectModel and a default NSManagedObjectContext. At least one of each of these must be instantiated and configured properly for Core Data to work. MagicalRecord provides this single method to configure your stack with a SQLite persistent store located in /Library/Application Support//.sqlite

setupAutoMigratingDefaultCoreDataStack

When you version your model, you will need to migrate your data. This method will do the same as the previous (above) method, but will also enable Auto Migrations.

setupCoreDataStackWithInMemoryStore;

Sometimes, such as when you're writing unit tests, you want your data to go away when your app terminates. This method will also set up a CoreData stack (as mentioned above) but instead of a SQLite store, it creates a persistent store in system memory (RAM).

setupCoreDataStackWithStoreNamed:(NSString *)storeName

Sometimes you want to customize the file name where your data resides. This method does the same as the first, namely setting up the core data stack, and placing a SQLite store in the specific location, but instead of .sqlite, the store is named storeName.sqlite

setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(NSString *)storeName

This does the same as the above method, but also enabled auto migrations. You'll need to do this when you version your model and have a simple migration that simply needs to be enabled.

You can read more on Core Data migrations on Apple's Core Data Reference Documentation

like image 101
casademora Avatar answered Oct 20 '22 14:10

casademora