alexey alexey - 3 months ago 24
Swift Question

what's wrong with my #if TARGET_OS_SIMULATOR code for Realm path definition?

I have this code

#if TARGET_OS_SIMULATOR
let device = false
let RealmDB = try! Realm(path: "/Users/Admin/Desktop/realm/Realm.realm")
#else
let device = true
let RealmDB = try! Realm()
#endif


device bool works fine, yet RealmDB works only for else condition.

Answer

TARGET_IPHONE_SIMULATOR macro doesn't work in Swift. What you want to do is like the following, right?

#if arch(i386) || arch(x86_64)
let device = false
let RealmDB = try! Realm(path: "/Users/Admin/Desktop/realm/Realm.realm")
#else
let device = true
let RealmDB = try! Realm()
#endif