views:

25

answers:

2

I would like to verify my Core Data store (SQLite file) before loading it so that if there is any corruption, the app won't simply crash and burn. Using the iPhone SDK, is there a way to verify an SQLite file (1) generally that it is not corrupted, and (2) more specifically, whether or not the SQLite file matches one of the possible data store versions for the app? The second part is important because I have built a backup system which allows users to load backed-up SQLite files into the app to replace the current data store.

A: 

Load it and catch the exception?

tc.
+1  A: 

TC's answer is probably the simplest. But you can also look at its metadata which will let you both know that A) it has Core Data metadata and B) what the hash values for its entities are which you can then use to confirm that you have a model which matches those hash values.

You can access the metadata without loading the store via the +[NSPersistentStore metadataForPersistentStoreWithURL:error: method.

Marcus S. Zarra
This looks promising--how would you compare this with the current metadata? I can't find any documentation online about what the metadata consists of.
Jason
Create a Core Data file and poke at it. There isn't any documentation on it but you can easily see what is inside.
Marcus S. Zarra