ios - 尽管尝试了官方 SO 答案的所有方法,但我找不到我的 .realm 文件

标签 ios swift cocoapods realm

运行 Realm 2.7.0、Swift 3.1、XCode 8.3.2

我有一个接受一些 JSON 的函数,它成功地从另一个 ViewController 传递过来,它的目的是创建一个类型为 LocationObject,我在以下文件:

import Foundation
import RealmSwift

class Location: Object
{
    dynamic var locName = ""
    dynamic var locCCode = ""
    dynamic var long = 0.0
    dynamic var lat = 0.0

}

我的函数如下所示:

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")
    }
}

函数末尾的print函数有效,说明前面几行创建和添加到Realm数据库的代码是有效的,但是我通过模拟器或设备上。

我尝试使用以下方法找到它/声明它的位置:

print(Realm.Configuration.defaultConfiguration.fileURL!)
let realm = Realm(path: "/Users/me/Desktop/TestRealm.realm")
debugPrint("Path to realm file: " + realm.configuration.fileURL!.absoluteString)

通过 (lldb) 我返回了 error: use of undeclared identifier 'Realm' 这也是引起关注的原因。我无法通过 Cocoapods 安装 Realm,不得不手动安装,相信我已经成功安装了。

我还尝试按照说明通过 Finder 查找设备和模拟器的文件,但均未成功。

最佳答案

我录制了一个短视频,从一个新的 Xcode 项目(使用 Xcode 8.3.2)开始,集成 Realm Swift,打印 Realm 的位置,在 Finder 中打开它,显示创建 Realm 后文件出现,并且可以使用 Realm Browser macOS 应用程序实时访问和更新它。希望这可以帮助您弄清楚您是否遗漏了一步,或者做的事情略有不同。

https://static.realm.io/debug/SO44171039.mov

关于ios - 尽管尝试了官方 SO 答案的所有方法,但我找不到我的 .realm 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44171039/

相关文章:

ruby - 如何使用 ruby​​ 和命令行工具在 mavericks 中正确安装 cocoapod?

iphone - 有没有办法获取有关上一首 iPod 歌曲的信息?

swift - PDFAnnotationSubType 持久时不保存墨水(iOS11、PDFKit)

ios - Pod 文件没有在我的项目中创建?

iOS 应用程序编译但 XCode 8.1 beta 给出错误消息说 "Module ' HockeySDK' not found”

swift - 变量类型 : global, swift 中的应用程序、 session 或 cookies 变量?

ios - 带有 unicode 的字符串和带有多行的 UILabel

ios - Facebook 和 Twitter 分享按钮停止工作

iOS 应用程序不断崩溃

swift - 音频流在哪里添加libjingle?