我可以与应用程序组共享iOS领域数据库吗?

时间:2017-06-04 01:09:42

标签: ios swift realm ios-app-group

我可以与应用程序组共享iOS领域数据库吗?如果有,怎么样?如果没有,我如何将我的Realm数据库共享给我的其他应用程序?

1 个答案:

答案 0 :(得分:7)

要在同一iOS应用程序组中的应用程序之间共享领域,您需要为领域指定一个公共位置:

import Cocoa

class MainWindowController: NSWindowController
{
    var secondaryViewController:NSViewController?

    override func windowDidLoad()
    {
        super.windowDidLoad()

        // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
    }

    @IBAction func segmentedControlDidChange(_ sender: NSSegmentedControl)
    {
        print("Index: \(sender.selectedSegment)")

        if sender.selectedSegment == 3 {
            if secondaryViewController == nil {
                let viewController = storyboard?.instantiateController(withIdentifier: "SecondaryViewController") as! NSViewController
                secondaryViewController = viewController
            }

            self.window?.contentViewController = self.secondaryViewController
        }
    }
}