iOS & Swift 공부 - Realm -> Basic Setup

김영채 (Kevin)·2021년 3월 18일
0

iOS & Swift

목록 보기
96/107
post-thumbnail

Realm Basic Setup


  • In the AppDelegate.swift file, don't forget to import RealmSwift and initialize it.
print(Realm.Configuration.defaultConfiguration.fileURL)

→ Use the above code to figure out where your Realm file is.

CMD + SHIFT + G (Finder)

→ to immediately navigate to the path printed in the console. (delete "file://").

let data = Data()
    data.name = "Kevin"
    data.age = 26
        
    do {
        let realm = try Realm()
        try realm.write {
            realm.add(data)
        }
    } catch {
       print("Error initializing realm \(error)")
    }

Initializing Realm for basic use

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
     print(Realm.Configuration.defaultConfiguration.fileURL)
        
    do {
        let realm = try Realm()
    } catch {
        print("Error initializing realm \(error)")
    }
        
    return true
}
profile
맛있는 iOS 프로그래밍

0개의 댓글