extension RLMRealm {
class func defaultRealm() -> RLMRealm! {
return RLMRealm.realmWithPath(testRealmPath(), readOnly: false, error: nil)
}
}
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-cocoa/9279bea0-1436-4eec-963c-d47a1f0a38f4%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "Realm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-cocoa...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
Hey Sean, yes I was able to figure this out. Are you still having trouble? Essentially what I did is create my own static helper. That's your best choice, don't rely on Realm.defaultRealm(). I have my on RealmManager class that is a singleton. I'm not crazy about this but I really needed to have something in place to run tests. It has 2 class methods, setupRealm and setupTestRealm. In my app delegate if I detect I'm running tests I call setupTestRealm and cut out early from the didFinishLaunching method. Otherwise if I run the app normally then it calls setupRealm. They do the same thing except that setupTestRealm changes the instance to point to my test.realm database file. This way when running tests anytime I do RealmManager.realm() it returns a realm to that test.realm file rather than the app's database file (db.realm). Let me know if you have questions or trouble. Happy to help out.Probably the most important part is this: if you are writing your app in Swift and want to run tests against code that uses Realm, do NOT, do NOT put those files in both the app and test targets. Leave it only in the app target but that means you *must* use access control (specifying public, private, etc.) to do testing and then import the app target in your tests (if app is called MyApp, then "import MyApp"). I ran into a lot of pain because Realm is really pushing the limits of Swift. With the approach of setting my files to be in both targets and being access control-less I would get sporadic dynamic casting errors (https://github.com/realm/realm-cocoa/issues/1044). Apple is aware that there are frustrations to testing when using Swift. Essentially two approaches, but if you want to test against Realm backed code make sure to use this approach: http://blog.diogot.com/blog/2014/08/23/swift_access_control_and_testing/ (what I outlined above).
--
You received this message because you are subscribed to the Google Groups "Realm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-cocoa...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-cocoa/216e6ebb-982a-46b7-8e90-7bdfc42709e2%40googlegroups.com.