-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
完成: iOS 10 中的 NSPersistentContainer #801
Conversation
申请校对 |
@owenlyn 好的 |
+1 |
@Graning 好的 |
* 校对者: | ||
|
||
|
||
|
||
|
||
|
||
Xcode 8 is here if you have not peeked at any of betas yet, you will find all kinds of new stuff. There is Swift 3 with [major changes](https://swifting.io/blog/2016/08/17/22-swift-3-access-control-beta-6?utm_source=swifting.io&utm_medium=web&utm_campaign=blog%20post), there are new frameworks like [SiriKit](https://swifting.io/blog/2016/07/18/20-sirikit-can-you-outsmart-provided-intents?utm_source=swifting.io&utm_medium=web&utm_campaign=blog%20post) and there are enhancements to existing ones like [notifications](https://swifting.io/blog/2016/08/22/23-notifications-in-ios-10?utm_source=swifting.io&utm_medium=web&utm_campaign=blog%20post). We have also received simplified Core Data stack in form of NSPersistentContainer that does heavy part of setup for us. Is it worth trying? Let's dig in and find out. | ||
Xcode 8 已经面世了,如果你还没有尝试过这个抢鲜测试版本,你会发现所有新的东西。这里有 Swift 4 [主要的更新](https://swifting.io/blog/2016/08/17/22-swift-3-access-control-beta-6?utm_source=swifting.io&utm_medium=web&utm_campaign=blog%20post),有新的框架,比如 [SiriKit](https://swifting.io/blog/2016/07/18/20-sirikit-can-you-outsmart-provided-intents?utm_source=swifting.io&utm_medium=web&utm_campaign=blog%20post) 和一些对现存特性的增强改进,比如 [notifications](https://swifting.io/blog/2016/08/22/23-notifications-in-ios-10?utm_source=swifting.io&utm_medium=web&utm_campaign=blog%20post). 我们也接收以 `NSPersistentContainer` 形式的简化版的 `Core Data` 堆,它为我们做了大部分的准备工作。它值得我们去尝试么?让我们开始深入挖掘这些新特性吧。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 如果你还没有尝试过这个测试版本,你将会发现各种新东西。
- notifications 这句后面为句号。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Xcode 8 正式版已经发布,如果你之前没尝试过beta版本,那么你会大呼过瘾,新东西很多。Swift 3[重磅更新]、各种新框架[比如SiriKit]、以及对现有框架的改进[比如notifications]。
还有简化 Core Data stack 设置的 NSPersistentContainer 类。/还有新的 NSPersistentContainer 类,极大简化了 Core Data stack 的使用。
这里有 - there is 这里是表示存在的意思,不必翻译成【这里有】,语句还是符合汉语习惯比较好。
我们也接收以 - We have also received 这里 We have ... received 表示的也是存在的意思,【我们】不必翻译出来。
does heavy part of setup - 这里我认为可以用意译。
stack 是一个术语,应该和 Core Data 联用,我认为不必写成汉字。
+多年来,在尝试了很多种 Core Data
堆之后,我们选定了两个简单的堆,融合成一个使用。
这句严重理解错误。我试着提供一种理解,并不是经过斟酌的译文,当然要翻译得简洁有难点,但是最重要的是【准确】:
长期以来,尝试过多种Core Data Stack配置方式之后,我们认定了一种简单的配置方式:两个context的stack架构,一个context保存(save)时,另一个context合并(merge)变化。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
附原文:Over years, after trying many Core Data stacks we have settled on simple two context stack with a merge on save.
|
||
#### Core Data stack prior to iOS10 | ||
#### `iOS 10` 之前的 `Core Data` 堆 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
要不把 “堆” 的 stack 也保留了,留下感觉怪怪的。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okey.
|
||
Over years, after trying many Core Data stacks we have settled on simple two context stack with a merge on save. Let's have a look at key components and wiring up. Link to the full version on GitHub is available in references. Code has been adjusted to Swift 3 and Xcode 8. | ||
多年来,在尝试了很多种 `Core Data` 堆之后,我们选定了两个简单的堆,融合成一个使用。让我们仔细看一下这些关键组件并开始连接使用他们。完整版本的 `Github` 连接在引用中能找到。代码已经适配到 `Swift 3` 和 `Xcode 8`。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
完整版本的 Github
“连接” 在引用中能找到。——链接而非连接。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after trying many Core Data stacks we have settled on simple two context stack with a merge on save. @owenlyn 你看一下这句的翻译。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(after trying many Core Data stacks) (we) (have settled) (on simple two context stack with a merge on save).
按照句子成分来看,我觉得翻译的挺符合作者原意的。不过按正常的英文形容词的顺序,原文应该是 "two simple context stack" 。然后我看了一下作者,他母语应该不是英语...
|
||
##### #3 | ||
|
||
Similarly to documents directory, this extracted `NSManagedObjectModel` getter is used to initialize `NSPersistentStoreCoordinator` with our model. | ||
和文件目录相似,他获得 `NSManagedObjectModel` 的 `getter` 方法,用它来初始化 有我们模型的 `NSPersistentStoreCoordinator`。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
“有我们模型的”前面多了一个空格
|
||
Simple answer is that `NSPersistentContainer` does all that for us. That is not good enough for a blog post explanation 😆. We will break it down to pieces as well. | ||
简单的答案是,`NSPersistentContainer` 已可以为我们代劳。对于一个博客文章的解释,这肯定不够 😆 。还是容我慢慢道来。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其实用博客来解释并不是非常好😆。
|
||
First, make sure to check full reference and look for properties or methods that you may need. We have covered that there are two initialisers, a convenience one that takes just string name and full one that takes also `NSManagedObjectModel`. | ||
首先,确保查阅了完整的参考资料,并且在寻找你所需要的属性或者方法。我们有概括道,有两个初始化器,一个快捷方法,它仅需要一个字符串名字和一个完整的,它也需要 `NSManagedObjectModel`。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们已经涵盖了两个初始化器,一个仅需要字符串名和完整采用NSManagedObjectModel
的快捷方法。
|
||
Luckily, with a small subclass of `NSPersistentContainer` we were back in the game and could use all goodies given by container. | ||
幸运的是,通过一个轻量的子类 `NSPersistentContainer`,我们又满血复活了,并且能使用那些容器类带来的好处。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们又满血复活了,并且能继续使用那些容器带来的好处。
|
||
Yes there is. The best way to find out is Apple's 'What's new in Core Data in iOS10' article (link below). Changes start from concurrency, context versioning, fetch requests, auto merging changes from parent context and end on … `NSFetchedResultsController` in macOS 10.12. | ||
是的,当然有。最佳的方法是通过 `Apple` 公司的官方推文 'Core Data 在 iOS 10 上的新特性'(链接如下)。这些改变从并发,`context` 版本,请求获取,自动融合来自父 `context` 变化和结束开始.... `NSFetchResultsController` 在 `macOS 10.12`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
链接如下? 链接呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Graning 英文原文里也没提到链接在哪里。。。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yifili09 那就删了吧
@yifili09 校对完成,刚好一天。 |
@owenlyn 啥子情况嘛 |
* 校对者: | ||
|
||
|
||
|
||
|
||
|
||
Xcode 8 is here if you have not peeked at any of betas yet, you will find all kinds of new stuff. There is Swift 3 with [major changes](https://swifting.io/blog/2016/08/17/22-swift-3-access-control-beta-6?utm_source=swifting.io&utm_medium=web&utm_campaign=blog%20post), there are new frameworks like [SiriKit](https://swifting.io/blog/2016/07/18/20-sirikit-can-you-outsmart-provided-intents?utm_source=swifting.io&utm_medium=web&utm_campaign=blog%20post) and there are enhancements to existing ones like [notifications](https://swifting.io/blog/2016/08/22/23-notifications-in-ios-10?utm_source=swifting.io&utm_medium=web&utm_campaign=blog%20post). We have also received simplified Core Data stack in form of NSPersistentContainer that does heavy part of setup for us. Is it worth trying? Let's dig in and find out. | ||
Xcode 8 已经面世了,如果你还没有尝试过这个抢鲜测试版本,你会发现所有新的东西。这里有 Swift 4 [主要的更新](https://swifting.io/blog/2016/08/17/22-swift-3-access-control-beta-6?utm_source=swifting.io&utm_medium=web&utm_campaign=blog%20post),有新的框架,比如 [SiriKit](https://swifting.io/blog/2016/07/18/20-sirikit-can-you-outsmart-provided-intents?utm_source=swifting.io&utm_medium=web&utm_campaign=blog%20post) 和一些对现存特性的增强改进,比如 [notifications](https://swifting.io/blog/2016/08/22/23-notifications-in-ios-10?utm_source=swifting.io&utm_medium=web&utm_campaign=blog%20post). 我们也接收以 `NSPersistentContainer` 形式的简化版的 `Core Data` 堆,它为我们做了大部分的准备工作。它值得我们去尝试么?让我们开始深入挖掘这些新特性吧。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Swift 3" 翻译成了 Swift 4...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@owenlyn
哈哈,我是多期待 4 的降临。。
|
||
Over years, after trying many Core Data stacks we have settled on simple two context stack with a merge on save. Let's have a look at key components and wiring up. Link to the full version on GitHub is available in references. Code has been adjusted to Swift 3 and Xcode 8. | ||
多年来,在尝试了很多种 `Core Data` 堆之后,我们选定了两个简单的堆,融合成一个使用。让我们仔细看一下这些关键组件并开始连接使用他们。完整版本的 `Github` 连接在引用中能找到。代码已经适配到 `Swift 3` 和 `Xcode 8`。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(after trying many Core Data stacks) (we) (have settled) (on simple two context stack with a merge on save).
按照句子成分来看,我觉得翻译的挺符合作者原意的。不过按正常的英文形容词的顺序,原文应该是 "two simple context stack" 。然后我看了一下作者,他母语应该不是英语...
|
||
##### #2 | ||
|
||
Extracted documents directory `NSURL` getter. `NSPersistentStoreCoordinator` uses it to create `NSPersistentStore` at given location. | ||
从 `NSURL` 文档中获得 `getter` 方法。`NSPersistentStoreCoordinator` 使用它在给定的位置创建 `NSPersistentStore`。 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted documents directory
NSURL
getter
建议翻译成
获取文档路径
NSURL
的 getter。
这里 Extracted documents directory 和 NSURL
应该是同位语吧?
“getter” 翻译成 “获取方法” 是不是会有歧义?所以保留不翻是不是更好?@Graning
|
||
#### Meet NSPersistentContainer | ||
#### 遇见 NSPersistentContainer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NSPersistentContainer 简介
|
||
##### #1 | ||
|
||
Here we can see the power of `NSPersistentContainer`. It does the entire work of #2, #3, #4, #5, #6 from former stack and to some extent frees us from implementing #1 and #7\. | ||
这里,我们能看到 `NSPersistentContainer` 的能力。它包括了整个 #2, #3, #4, #5, #6 的工作,从之前的堆到一些额外的扩展,把我们从 #1 和 #7 中解放出来。 | ||
|
@sqrthree 校对完啦 |
@yifili09 两位校对者都已经校对完了,可以来修改了哈。 |
8b7c193
to
bf83e34
Compare
|
||
Yes there is. The best way to find out is Apple's 'What's new in Core Data in iOS10' article (link below). Changes start from concurrency, context versioning, fetch requests, auto merging changes from parent context and end on … `NSFetchedResultsController` in macOS 10.12. | ||
是的,当然有。最佳的方法是通过 `Apple` 公司的官方推文 'Core Data 在 iOS 10 上的新特性'。这些改变从并发,`context` 版本,请求获取,自动融合来自父 `context` 变化和结束开始.... `NSFetchResultsController` 在 `macOS 10.12`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『这些改变从并发』后面的一系列逗号是不是不太合适呀。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(⊙o⊙)…其实我指的是逗号,似不似应该换成顿号?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉这句话好像只说了一半,从...开始,下文没了?还是我理解有问题?
|
||
Wait… What? Are there more changes? | ||
稍等以下... 啊?还有其他的改变么? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
『以下』?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
果然要 稍等一下。。 😭
987d5d4
to
287e0f2
Compare
|
||
是的,当然有。最佳的方法是通过 `Apple` 公司的官方推文 'Core Data 在 iOS 10 上的新特性'。这些改变从并发,`context` 版本,请求获取,自动融合来自父 `context` 变化和结束开始.... `NSFetchResultsController` 在 `macOS 10.12`. | ||
是的,当然有。最佳的方法是通过 `Apple` 公司的官方推文 'Core Data 在 iOS 10 上的新特性'。这些改变从并发、`context` 版本、请求获取、自动融合来自父 `context` 变化等开始,以在 `macOS 10.12` 中的 `NSFetchResultsController` 结束。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💥 Ready For Merge 💥
@sqrthree