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.
As of Xcode 9.3+ Swift now supports #if targetEnvironment(simulator)
to check if you're building for Simulator.
Please stop using architecture as a shortcut for simulator. Both macOS and the Simulator are x86_64 which might not be what you want.
// ObjC/C:
#if TARGET_OS_SIMULATOR
// for sim only
#else
// for device
#endif
// Swift:
#if targetEnvironment(simulator)
// for sim only
#else
// for device
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With