I have an app with a today extension. In appDelegate.swift for the main app:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let directory: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.Hobo.RealmDatabase")!
var config = Realm.Configuration()
config.fileURL = directory.filePathURL?.URLByAppendingPathComponent("db.realm")
Realm.Configuration.defaultConfiguration = config
return true
}
In my todayExtension's viewDidload:
override func viewDidLoad() {
super.viewDidLoad()
let directory: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.Hobo.RealmDatabase")!
var config = Realm.Configuration()
config.fileURL = directory.filePathURL?.URLByAppendingPathComponent("db.realm")
Realm.Configuration.defaultConfiguration = config
let realm = try! Realm()
}
When I create an object in my main app, it persists in the database. However when I try to read the number of objects from todayExtensionViewController, it returns 0, meaning no objects were created.
I am confused because since both the apps getting the same Realm data from the same location, isn't it supposed to "share" the data?
I'm using groups to share data between apps.
Thanks in advance!