ManagedObjectContext 语法
ManagedObjectContext Syntax
所以,它告诉我:
init()
was deprecated in IOS 9.0: Use -initWithConcurrencyType
:
instead
var managedObjectContext = NSManagedObjectContext()
这是我的代码。也报错了,我该怎么改?
由于 iOS 9 NSManagedObjectContext()
已弃用,建议创建一个 NSManagedObjectContext
,如提示的那样,改为 -initWithConcurrencyType:
。
在 iOS 9 中创建 NSManagedObjectContext
时的用法:
let managedObjectContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
对于-initWithConcurrencyType:
,我们需要指定并发类型。
上面的示例创建了一个 .MainQueueConcurrencyType
,它是可以指定的三个之一:
case ConfinementConcurrencyType
Specifies that the context will use the thread confinement pattern.
case PrivateQueueConcurrencyType
Specifies that the context will be associated with a private dispatch queue.
case MainQueueConcurrencyType
Specifies that the context will be associated with the main queue.
随着 NSManagedObjectContext()
的弃用,如果我没记错的话,默认的类型是 .ConfinementConcurrencyQueue
。
如果您正在处理 UI 元素(即由此更新 textLabel
),请继续讨论主题,请使用 .MainQueueConcurrencyQueue
.
所以,它告诉我:
init()
was deprecated in IOS 9.0: Use -initWithConcurrencyType
: instead
var managedObjectContext = NSManagedObjectContext()
这是我的代码。也报错了,我该怎么改?
由于 iOS 9 NSManagedObjectContext()
已弃用,建议创建一个 NSManagedObjectContext
,如提示的那样,改为 -initWithConcurrencyType:
。
在 iOS 9 中创建 NSManagedObjectContext
时的用法:
let managedObjectContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
对于-initWithConcurrencyType:
,我们需要指定并发类型。
上面的示例创建了一个 .MainQueueConcurrencyType
,它是可以指定的三个之一:
case ConfinementConcurrencyType
Specifies that the context will use the thread confinement pattern.
case PrivateQueueConcurrencyType
Specifies that the context will be associated with a private dispatch queue.
case MainQueueConcurrencyType
Specifies that the context will be associated with the main queue.
随着 NSManagedObjectContext()
的弃用,如果我没记错的话,默认的类型是 .ConfinementConcurrencyQueue
。
如果您正在处理 UI 元素(即由此更新 textLabel
),请继续讨论主题,请使用 .MainQueueConcurrencyQueue
.