0

I'm creating an iOS App using Realm. I've correctly installed all the frameworks as well as the Realm Browser and would now like to see 1. if my data structure has been created and implemented in realm appropriately and 2. updates to the data file when they are made.

I've followed the instructions here How to find my realm file? and have gotten the path:

file:///Users/carltonivy/Library/Developer/CoreSimulator/Devices/464A53E1-0317-408F-B851-EA758199BA61/data/Containers/Data/Application/B8754857-4A4D-43B9-8E33-57113E27A545/Documents/default.realm

as the result, but when I navigate there I can't find any kind of default.realm, only files ending in .sqlite


Questions/Resolutions

The only things I've done in my project are creating models/relationships and added import RealmSwift to my .swift files.

Do I need to add some blocks of code somewhere to initialize the .realm file/database? Is there some kind of data layer I need to create like something you would use with MVC C# (the only other language I have experience in)? Am I missing anything conceptually about Realm? I've used code first databases many times before.

Thanks.

Community
  • 1
  • 1
Carlton
  • 53
  • 1
  • 1
  • 3

1 Answers1

0

You're on the right track! You're correct in that the default.realm file isn't created until Realm is initialized for the first time in your code.

You do that by calling

let realm = try! Realm()

The first time this is called, Realm will collect all of the Realm model classes you've created in your app, and will create a new default.realm file with the appropriate backing schema for those models.

I'm not sure why you'd have .sqlite files in there as well; that's definitely not Realm's doing. It's possible if you have other dependencies in there that rely on data persistence (An analytics library for example), they're internally creating those files.

TiM
  • 15,812
  • 4
  • 51
  • 79
  • Awesome thanks. I think the .sqlite files are CoreData things that I included when creating the project. So would I call that method somewhere in AppDelegate? – Carlton Dec 08 '16 at 01:59
  • Ahh, that would explain it. Yeah, you can call it in the `didFinishLaunchingWithOptions` delegate method, but usually you just only need to call it when you need to access the database for the first time. :) – TiM Dec 08 '16 at 18:38