未分類

Realmでモデル定義を変更した際に起こるエラーの対処法

投稿日:2020年8月9日 更新日:

Realmでモデル定義を変更するとエラーが出る。
マイグレーションをすることで解決する。

AppDelegate.swiftのfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool{}に以下のコードを追加する。
import RealmSwiftも追記。

import UIKit
import RealmSwift //←追記

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        //(ここから)
        // Configurationを生成
        var config = Realm.Configuration()
        config.schemaVersion = 1 //最初は0となっているので1以上に変える
        //(ここまで追記)
        
        return true
    }

スキーマは最初0になっているので、1以上に変更する。
以降、モデル定義を変更する度に数字を増やしていくとよい。

クリーンビルドもする。

-未分類

執筆者:

関連記事

no image

UIColorをRGBで指定する

label.textColor = UIColor(displayP3Red: 255/255, green: 126/255, blue: 121/255, alpha: 1) 参考:https:/ …

no image

動画の速度を遅くしてクリップを引き伸ばす方法

commnd + R スロー・早送りで速度を変更できる。 参考: Premiere Pro 再生速度を変更(早回し・スローモーション動画)する手っ取り早い方法

六角形とパスでモーショングラフィクスを作る

六角形のシェイプ と、パスで描いた線を使ってモーショングラフィクスを作る。 六角形は回転しながら外半径を大きくする。 線のパスは「追加」→「パスのトリミング」→「開始点」「終了点」を調整して、動きをつ …

no image

DateFormatterの使い方

Date型の日付を文字列にして表示する。 let date = Date() import Foundation //フォーマットを指定 let formatter = DateFormatter() …

no image

文字列の先頭から何文字を取り出す

文字列の先頭から、または後ろから、任意の数の文字を取り出す方法。 let text = “こんにちは、世界” //先頭から5文字を取り出す let first = String(text.prefix …