#前提・実現したいこと
Xcode にて Realm Swift を利用しアプリを App Store に公開しています。
この度、データモデルのプロパティを1つ増やすために、マイグレーションが必要になると思い
AppDelegate内に実装しましたが、エラーが発生してしまいます。
おそらく、マイグレーションの方法が間違っていて失敗しているとは思うのですが、
か行ける方法が解りませんでした。
#発生している問題・エラーメッセージ
objc[29350]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x11f1e0cc0) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x11eff76f0). One of the two will be used. Which one is undefined. fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=10 "Migration is required due to the following errors: - Property 'RegisteredUQ.isCalculationTarget' has been added." UserInfo={NSLocalizedDescription=Migration is required due to the following errors: - Property 'RegisteredUQ.isCalculationTarget' has been added., Error Code=10}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-802.0.53/src/swift/stdlib/public/core/ErrorType.swift, line 182 (lldb)
#該当のソースコード
##データモデル
swift
1import RealmSwift 2 3class RegisteredUQ: Object { 4 5 // Bool, Int, Float, Double, String, NSData(), NSDate(), List<Class>() 6 7 // SchemaVersion 0 8 dynamic var id = 0 9 dynamic var useDate = NSDate() 10 dynamic var usedFor = "" 11 dynamic var usePeriod = 0.0 12 13 // SchemaVersion 1 14 dynamic var isCalculationTarget = true 15 16 override static func primaryKey() -> String? { 17 return "id" 18 } 19}
##AppDelegate
swift
1import UIKit 2import UserNotifications 3import RealmSwift 4 5@UIApplicationMain 6class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate { 7 8 var window: UIWindow? 9 10 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 11 12 realmMigration() 13 14 中略 15 16 return true 17 } 18 19 中略 20 21 // Realmのマイグレーション 22 func realmMigration() { 23 let config = Realm.Configuration( 24 // 新しいスキーマバージョンを設定します。以前のバージョンより大きくなければなりません。 25 // (スキーマバージョンを設定したことがなければ、最初は0が設定されています) 26 schemaVersion: 1, 27 28 // マイグレーション処理を記述します。古いスキーマバージョンのRealmを開こうとすると 29 // 自動的にマイグレーションが実行されます。 30 migrationBlock: { migration, oldSchemaVersion in 31 // 最初のマイグレーションの場合、`oldSchemaVersion`は0です 32 if (oldSchemaVersion < 1) { 33 // 何もする必要はありません! 34 // Realmは自動的に新しく追加されたプロパティと、削除されたプロパティを認識します。 35 // そしてディスク上のスキーマを自動的にアップデートします。 36 } 37 }) 38 39 // デフォルトRealmに新しい設定を適用します 40 Realm.Configuration.defaultConfiguration = config 41 42 // Realmファイルを開こうとしたときスキーマバージョンが異なれば、 43 // 自動的にマイグレーションが実行されます 44 let realm = try! Realm() 45 46 print(realm, "Realm") 47 print(config,"Realm Version") 48 } 49}
#試したこと
試しにスキーマバージョンを10にして見ても同じくエラーでした。
#補足情報(言語/FW/ツール等のバージョンなど)
Xcode 8.3.3 Swift 3.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/28 23:40
2017/07/29 00:45
2017/07/29 01:36