tags:

views:

73

answers:

1

I have database dump and I want load it to sqlite database on iphone at runtime. How i can do it from code?

+1  A: 

It is unclear what "database dump" is, but assuming it is a sqlite database that matches the data model on the iPhone it is easy--but with a trick Xcode throws in.

1) Rename the file from xxx.sqlite to xxx.bin. Other extensions should also work but if you leave it .sqlite Xcode will make changes in the file and it will not match the data model and crash. This little feature of Xcode cost me 1/2 a day.

2) Copy the database to the resources folder in Xcode.

3) On launch copy the database to the Documents directory renaming the extension to "sqlite".

zaph
Xcode will make changes in the file and it will not match the data model and crash.Do you have crash at app launch!?
Sergey Zenchenko
zaph
I have crahs at launch 8 CoreData 0x000994be -[NSSQLConnection prepareAndExecuteSQLStatement:] + 269 CoreData 0x000be14c -[_NSSQLiteStoreMigrator performMigration:] + 24410 CoreData 0x000b6c60 -[NSSQLiteInPlaceMigrationManager migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:] + 104011 CoreData 0x000aceb0 -[NSStoreMigrationPolicy(InternalMethods) migrateStoreAtURL:toURL:storeType:options:withManager:error:] + 9212 CoreData
Sergey Zenchenko
Be sure to delete the old app from "~/Library/Application Support/iPhone Simulator/User/Applications/xxx" and/or the device. CoreData's basic error message seems to be: CRASH!
zaph