I am new to both Realm and iOS development and I am stuck due to this error. I downloaded the latest version of Realm i.e. 0.98.0 and followed the steps mentioned in the Getting Started section
If using Realm in an iOS, watchOS or tvOS project, create a new “Run Script Phase” in your app’s target’s “Build Phases” and paste the following snippet in the script text field:
bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Realm.framework/strip-frameworks.sh"
As mentioned in the answer to the following question I added $(PROJECT_DIR) in the Framework Search Paths
How to add the parent path to RealmSwift.framework in the “Framework Search Paths” section?
After that I created a class called Dog and added the following code in AppDelegate.swift
let myDog = Dog()
myDog.name = "Rex"
myDog.age = 1
print("name of dog: \(myDog.name)")
// Get the default Realm
let realm = try! Realm()
// Persist your data easily
try! realm.write {
realm.add(myDog)
}
When I try to build the project I get an error "Use of unresolved identifier 'Realm'" on the following line :
let realm = try! Realm()
I have tried creating new projects and carefully following the above steps but I still get the error. For Step 2 I tried added the framework with both the "Create groups" and "Create folder references" options while keeping "Copy items if needed" checkbox ticked.
I am using XCode 7.2.1, OS 10.11.13 and Swift 2.1.1. I do not have Cocoapods installed at the moment
Am I missing some step somewhere? Any help would be really appreciated.
The issue was the missing import statement. The examples folder helped in solving the issue.
import RealmSwift
Having worked with Java and the auto import feature in Eclipse this took a little getting used to.
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