I want to use the Realm file created in Realm Studio in my own application.

Asked 1 years ago, Updated 1 years ago, 86 views

I have a question about Realm.
I am currently developing an application using SwiftUI, but what should I do if I use the Realm file created by Realm Studio within the application?

let realm=try!Realm()
let config = Realm.Configuration(fileURL:URL("filetopath")!, readOnly:true)
Realm.Configuration.defaultConfiguration=config

I've been here, but

let data=realm.objects (Hoge.self)
print(data)

It does not show the contents.

I have hardly touched Realm, and I am a beginner at Swift, so I would appreciate it if you could tell me.

swift realm swiftui

2022-09-30 19:22

1 Answers

Self-resolved.

I put the Realm file in the project folder and I was able to code it as follows.

let realm=try!Realm (fileURL: URL (string: Bundle.main.path (forResource: "default", ofType: "realm")!)


2022-09-30 19:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.