Intermediate Realm on iOS - Part 2: Bundled Data | Ray Wenderlich

Learn how to bundle with your app a realm file with initial data for your users to use immediately upon the first launch.

This is a companion discussion topic for the original entry at

Hello @icanzilb.
Thanks for the detailed tutorial on Realm. I have one question.

Whenever the app starts, the first time we use the main configuration the following will run once:

private static var copyInitialFile: Void = {
      Bundle.main.url(forResource: "default_v1.0", withExtension: "realm")!,
      to: RealmConfig.mainConfig.fileURL!)

Is this needed in every app launch? Wouldn’t it suffice to happen once during the very first launch of the app (after its installation) and then never happen again, since we will have the initial data in the Documents folder?

Hi Theo, yes the code copies the file just once - it happens when the app runs for the first time

For the first time ever, or every time it started after a deallocation from the system or a user app-kill?

Well if you just have a look at the copyInitialData you will see that it copies the file any time it doesn’t find the required realm file in the Library folder. So if the user deletes the file the app will copy the initial version next time the app starts.

Bummer, you are right, sorry. Thanks.

Hi @icanzilb

That was very helpful ,
I did the same thing but I move the file to Library Folder

NOW I need to move it to App Group so I can use Realm file in App Extensions

How Can I move Realm File from Library Folder to App Group ?

Could you Help me ?

There is an article on realm’s website touching on that topic: