如何将领域数据库迁移到应用程序组?

编程入门 行业动态 更新时间:2024-10-25 17:20:28
本文介绍了如何将领域数据库迁移到应用程序组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

最近在应用和扩展程序之间添加了共享Realm数据,真的很兴奋。该文档详细说明了如何将默认域设置为app组目录,我已经开始工作了。

Really excited about the recent addition of sharing Realm data between apps and extensions. The documentation details how to set the default realm to the app group directory, I've got that working.

这就是我所坚持的 - 将旧数据库转移到应用程序组中的新位置的最佳方法是什么?

Here's what I'm stuck on -- what's the best way to transfer the old database to the new location in the app group?

推荐答案

基于@segiddins评论,我决定使用NSFileManager将旧数据库移动到应用程序组:

Based on @segiddins comment, I decided to go with moving the old database to the app group using NSFileManager:

let fileManager = NSFileManager.defaultManager() //Cache original realm path (documents directory) let originalDefaultRealmPath = RLMRealm.defaultRealmPath() //Generate new realm path based on app group let appGroupURL: NSURL = fileManager.containerURLForSecurityApplicationGroupIdentifier("group.AppGroup")! let realmPath = appGroupURL.path!.stringByAppendingPathComponent("default.realm") //Moves the realm to the new location if it hasn't been done previously if (fileManager.fileExistsAtPath(originalDefaultRealmPath) && !fileManager.fileExistsAtPath(realmPath)) { var error: NSError? fileManager.moveItemAtPath(originalDefaultRealmPath, toPath: realmPath, error: &error) if (error != nil) { println(error) } } //Set the realm path to the new directory RLMRealm.setDefaultRealmPath(realmPath)

更多推荐

如何将领域数据库迁移到应用程序组?

本文发布于:2023-11-25 13:46:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629997.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   应用程序   领域   数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!