实现Core Data to watchOS 2.0 [英] Implementing Core Data to watchOS 2.0

查看:145
本文介绍了实现Core Data to watchOS 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是WatchKit的新手,我正试图将Core Data添加到我的WatchKit扩展中。到目前为止,我已经在我的WatchKit扩展中创建了一个数据模型,但我坚持实现其余的核心数据堆栈。



是创建核心数据模型的过程并初始化Core数据栈与iOS相同或有任何差异我应该注意?



此外,我初始化核心数据堆栈在 ExtensionDelgate.swift 或者应该将其初始化到其他地方吗?

解决方案

watchOS核心数据栈与iOS相同。实际上,您可以在iOS和watchOS目标之间共享这个公共代码(甚至是一个通用的数据模型)。​​



您可以在应用程序启动时初始化堆栈,将该代码从(app或)扩展代理中移出到共享管理器中,当您第一次从模型中获取数据时,该管理器会初始化。



直到我的接口控制器的 awakeWithContext 加载我的数据(它延迟初始化我的经理的堆栈)。



寻找一个工作示例,Jesse Squires有一个优秀的Swift Core数据栈,您可能会发现它有帮助。 p>

I am pretty new to WatchKit, and I am trying to add Core Data to my WatchKit extension. So far I have created a Data Model in my WatchKit extension, but I am stuck on implementing the rest of the Core Data stack.

Is the process of creating Core Data models and initializing the Core Data stack identical to iOS or are there any differences I should be aware of?

Also, do I initialize the Core Data stack in the ExtensionDelgate.swift or should I initialize it somewhere else?

解决方案

The process of setting up the watchOS Core Data stack is identical to iOS. In fact, you can share that common code (and even a common data model) between your iOS and watchOS targets.

You can initialize your stack when your application launches, or move that code out of the (app or) extension delegate into a shared manager, which gets initialized the first time you need to obtain data from your model.

I actually wait until my interface controller's awakeWithContext to load my data (which lazily initializes my manager's stack).

If you're looking for a working example, Jesse Squires has an excellent Swift Core Data stack which you might find helpful.

这篇关于实现Core Data to watchOS 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆