Realm data sharing with WatchOS

In my project, I want to use the same Realm database with my iOS 10 application and my watchOs 3 application at the same time. So, I made adding frameworks to embedded binaries for three different purposes. This happened very well, but the watchKit extension does not seem to recognize objects created by me in the iOS environment. How is it possible to have a common Kingdom database between these two devices?

+4
source share
2 answers

Update: Well, thanks to the chrisamanse heads-up, I did some more research on this.

, watchOS 2. , ; - .

, , Realm , , WatchConnectivity.


: iOS ( Today, watchOS) . . Realm (.. "" ), watchOS .

, " " iOS, , iOS, watchOS, Realm, .

, App Groups , , Realm .

let sharedContainerURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.my.appgroups.bundleid")!
let realmURL = sharedContainerURL.appendingPathComponent("SharedRealm.realm")

let realmConfiguration = Realm.Configuration()
realmConfiguration.fileURL = realmURL
let realm = try! Realm(configuration: realmConfiguration)

- Realm, , , API Swift .

+6

Swift 3

Realm db :

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)
0

Source: https://habr.com/ru/post/1655504/


All Articles