CoreDataãçšããiOSã¢ããªã§sqliteãã¡ã€ã«ãpreloadããïŒswiftçïŒ
ããããããš
ã¢ããªãç«ã¡äžãã£ãŠããcsvãplistããããŒã¿ãããŒãããŠCoreDataã®sqliteãã¡ã€ã«ã«ããŒã¿ãå ¥ããã®ã§ã¯ãªãããããããå¥ã«äœã£ãŠãããsqliteãã¡ã€ã«ããããŒããããããæççªçµã®ã20åç ®èŸŒãã ç¶æ ããã¡ãã§ããçã«ã
ç°å¢
xcode6 beta7
MacOS 10.9
iOS 7.1.3
MagicalRecord
ã§ããããã³ãŒã
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. let fileManager = NSFileManager.defaultManager() // file URL to preload let preloadSQLiteURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(âmyData", ofType: "sqlite")!) // file URL to default sqlite file let storeSQLiteURL = NSPersistentStore.MR_urlForStoreName("myData.sqlite") var err:NSError? = NSError() if fileManager.fileExistsAtPath(storeSQLiteURL.path!) { // if default sqlite file already exists, delete it. fileManager.removeItemAtURL(storeSQLiteURL, error: &err) } // copy preload sqlite file. fileManager.copyItemAtURL(preloadSQLiteURL, toURL: storeSQLiteURL, error:&err) // initialize MagicalRecord with preloaded sqlite file MagicalRecord.setupCoreDataStackWithAutoMigratingSqliteStoreNamed("myData.sqlite") return true }
ã¯ãŸããã€ã³ã
fileãæ¢ã«ååšãããš copyItemAtURL ã倱æãããªããŠãããããŒãâŠ
çµå±CSVèªãŸããŠsqliteãã¡ã€ã«äœæããããã ãã®projectãå¥ã«äœã£ã¡ãã£ããâŠ
iOSã·ãã¥ã¬ãŒã¿ã§ãã£ããsqliteãã¡ã€ã«ãfinderããæŸããã£ãŠããããªäººãèšã£ãŠããã©åºãŠããªããâŠ
仿¹ãªãsqliteãã¡ã€ã«äœãã ãã®projectã§itunesãã¡ã€ã«åæãããŠåŒ·åŒã«åãåºãããâŠ
åèæç®
MagicalRecordã§SQLiteåæããŒã¿ãã³ããŒãã














