Share Realm Data with WatchOS

后端 未结 2 2074
小鲜肉
小鲜肉 2021-01-13 04:07

In my project I want to use one Realm Database with my iOS 10 application and my watchOs 3 application at the same time. So what I did was adding the frameworks to the embed

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-13 04:43

    For Swift 3

    I used the following code to share Realm db between app and app extension:

    let sharedDirectory: URL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.your.app")! as URL
    let sharedRealmURL = sharedDirectory.appendingPathComponent("db.realm")
    Realm.Configuration.defaultConfiguration = Realm.Configuration(fileURL: sharedRealmURL)
    

提交回复
热议问题