Realm - Add file with initial data to project (iOS

2020-02-16 08:18发布

I'm developing an application for iOS using swift and chose Realm as a database solution for it. I wrote default data in AppDelegate using write/add function from realm docs and it works just fine. So after first launch I have a *.realm file with my initial data. In Realm documentation I found a section called "Bundling a Realm with an App", I add my *.realm file to project and to Build Phases as it written.

And I can't understand what I should do next (and part about compressing a *.realm file). I've tried to understand a code from Migration Example but I don't know Obj-C well.

Please give as clear steps as you can to add *.realm file with initial data to swift ios project and load this data to the Realm db with the first launch.

7条回答
干净又极端
2楼-- · 2020-02-16 08:51

Download Realm Studio in your system. Then print the path from Xcode and copy it:

print(Realm.Configuration.defaultConfiguration.fileURL!)

Then open the terminal and write:

open //file path

It will open the file in Realm Studio and you can see your model data there.

查看更多
登录 后发表回答