Pan MluvĨí Pan MluvĨí - 8 months ago 61
Swift Question

Realm: Bundling a Realm with an App

I want to ship my app with several databases.

1) I have a random generated ".csv" file converted with Realm Browser to "default.realm".

2) I put it in /project_name/project_name/Resources and drop it inside Xcode to project files.

3) I checked "Copy bundle resources"enter image description here


import RealmSwift

class CarItem: Object {
dynamic var id = String()
dynamic var first_name = String()

In ViewDidLoad wanted to return results from file

override func viewDidLoad() {

let conf = Realm.Configuration(
fileURL: NSBundle.mainBundle().URLForResource("default", withExtension: "realm"),
readOnly: true)

let realm = try! Realm(configuration: conf)
let results = realm.objects(Item.self)

5) But results are empty (database have 1000 rows all filled with data).... what am i down wrong?


CarItem.self replace Item.self ?