現在、SwiftでRealmを勉強中です。簡単なクイズアプリを作ってみようと思い、CSVをRealm Browserにインポートしdefault.realmを作成しました。
まず始めに問題文(Q)をデバッグエリアに表示させようと思ったのですが、エラーになりました。
エラー内容を見る限り、Migrationに関するエラーだと思うのですが、色々サイトを見ても解決方法が理解できませんでした。
どなたか助けていただけるとありがたいです。
Swift
1 2import UIKit 3import RealmSwift 4 5class realm_test:Object { 6 dynamic var Q:String = "" 7 dynamic var A1:String = "" 8} 9 10class ViewController: UIViewController { 11 12 private var Questions:[String] = [] 13 14 override func viewDidLoad() { 15 super.viewDidLoad() 16 // Do any additional setup after loading the view, typically from a nib. 17 18 getAllQuestions() 19 20 } 21 22 override func didReceiveMemoryWarning() { 23 super.didReceiveMemoryWarning() 24 // Dispose of any resources that can be recreated. 25 } 26 27 28 func getAllQuestions() { 29 let config = Realm.Configuration( 30 fileURL: NSBundle.mainBundle().URLForResource("default", withExtension: "realm"), 31 readOnly: true) 32 33 let realm = try! Realm(configuration: config) 34 35 let results = realm.objects(realm_test).filter("Q != ''") 36 37 for i in 0 ..< results.count { 38 Questions.append(results[i].Q) 39 } 40 41 print("getAllQuestions=\(results)") 42 } 43 44 45} 46 47
エラー
fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=10 "Migration is required due to the following errors: - Property 'A2' is missing from latest object model. - Property 'A3' is missing from latest object model. - Property 'A4' is missing from latest object model. - Property 'A5' is missing from latest object model." UserInfo={NSLocalizedDescription=Migration is required due to the following errors: - Property 'A2' is missing from latest object model. - Property 'A3' is missing from latest object model. - Property 'A4' is missing from latest object model. - Property 'A5' is missing from latest object model., Error Code=10}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-703.0.18.8/src/swift/stdlib/public/core/ErrorType.swift, line 54
default.realm
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/10 01:46