我有一个领域文件,其中已经装有在将应用程序加载到设备上时需要存在的数据。
我应该怎么做才能将领域文件放到我的设备上进行测试,当有人从应用商店下载应用程序时,我需要做些什么来确保它已经存在?
我正在使用Swift。
将数据库文件添加到Xcode项目中,即“ preloaded.realm”。确保在首次放入文件时选择添加到目标。
然后(从迁移示例中获取),您可以执行类似的操作将预加载的文件复制到默认目录中。这将创建一个读/写领域
// copy over old data files for migration
let defaultPath = RLMRealm.defaultRealmPath()
let defaultParentPath = defaultPath.stringByDeletingLastPathComponent
let v0Path = NSBundle.mainBundle().resourcePath!.stringByAppendingPathComponent("preloaded.realm")
NSFileManager.defaultManager().removeItemAtPath(defaultPath, error: nil)
NSFileManager.defaultManager().copyItemAtPath(v0Path, toPath: defaultPath, error: nil)
这是该通用代码的链接https://github.com/realm/realm-cocoa/blob/master/examples/ios/swift-2.2/Migration/AppDelegate.swift
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句