Reputation: 331
Running Realm 2.7.0, Swift 3.1, XCode 8.3.2
I have a function that takes in some JSON, successfully passed from another ViewController, and its purpose is to create an Object
of type Location
which I've made in the following file:
import Foundation
import RealmSwift
class Location: Object
{
dynamic var locName = ""
dynamic var locCCode = ""
dynamic var long = 0.0
dynamic var lat = 0.0
}
and my function looks like this:
func addLocation(_ passedArray: [[String: AnyObject]], row: Int)
{
var dict = passedArray[row]
let title = dict["title"] as! String
let countryCode = dict["countryCode"] as! String
let lat = dict["lat"] as! Double
let long = dict["lng"] as! Double
//let latLong = CLLocation(latitude: lat, longitude: long)
let newLocation = Location()
newLocation.locName = title
newLocation.locCCode = countryCode
newLocation.long = long
newLocation.lat = lat
print(newLocation)
let realm = try! Realm()
try! realm.write
{
realm.add(newLocation)
print("Added \(newLocation.locName) to the Realm Database")
}
}
The print
function at the end of the function works, indicating that the previous lines of code creating and adding to the Realm Database are working, but I can neither find it when running my App through the Simulator or on Device.
I have tried using the following to find it/declare its location:
print(Realm.Configuration.defaultConfiguration.fileURL!)
let realm = Realm(path: "/Users/me/Desktop/TestRealm.realm")
debugPrint("Path to realm file: " + realm.configuration.fileURL!.absoluteString)
Through (lldb)
I get back error: use of undeclared identifier 'Realm'
which is cause for concern too. I was unable to install Realm through Cocoapods and had to do so manually and believe that I had managed to do so successfully.
I've also tried following the instructions to find the files through Finder without success, for both Device and Simulator.
Upvotes: 0
Views: 65
Reputation: 14409
I've recorded a short video starting from a new Xcode project (with Xcode 8.3.2), integrating Realm Swift, printing the location of the Realm, opening that in Finder, showing that the file appears once the Realm is created, and that it can be accessed and updated in realtime using the Realm Browser macOS app. Hopefully this helps you figure out if you're missing a step, or doing something slightly differently.
https://static.realm.io/debug/SO44171039.mov
Upvotes: 2