I have an error (yellow warning) on my model on line:
var managedObjectContext = NSManagedObjectContext()
'init()' was deprecated in iOS 9.0: Use -initWithConcurrencyType: instead
What is causing this? How can I fix this issue?
Change it to:
var managedObjectContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
You can download Apple's document to see more details.
NSConfinementConcurrencyType
Specifies that the context will use the thread confinement pattern.
Available in iOS 3.0 and later.
Deprecated in iOS 9.0.
Or Command+Click "NSManagedObjectContext" direct to NSManagedObjectContext.h:
@available(iOS, introduced=3.0, deprecated=9.0, message="Use another NSManagedObjectContextConcurrencyType")
case ConfinementConcurrencyType
@available(iOS, introduced=3.0, deprecated=9.0, message="Use -initWithConcurrencyType: instead")
public convenience init()
So it seems NSManagedObjectContext() use "ConfinementConcurrencyType" to init.When Apple deprecated "ConfinementConcurrencyType" in iOS 9.0,for the sake of coherence,Apple did not change the behavior of init() method. So you'd better use another NSManagedObjectContextConcurrencyTypes( PrivateQueueConcurrencyType, MainQueueConcurrencyType) with another init method:
init(concurrencyType: NSManagedObjectContextConcurrencyType)
Apple changed how core data works. Don't use init(), use initWithConcurrencyType instead as required/recommended.
The underlying reason is related to thread safety and asynchronous access to core data objects.
In general, when Apple tells you that something is deprecated, you will always get a message like
'init()' was deprecated in iOS 9.0: Use -initWithConcurrencyType: instead
And clearly, what you need to do is follow the very strong hint that you were given: Don't use init. Read up what initWithConcurrencyType: does, figure out what is the right way for you to call it, and replace your init call with a call to initWithConcurrencyType:
Take this as an answer to the general question, because really, you should be able to figure this out yourself.