A Warning "'Init()' Is Deprecated". [Swift, iOS App, Learning Model]

Swift - 'init()' was deprecated in iOS 9.0: Use -initWithConcurrencyType: instead

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)

NSManagedObjectContext(): `init()` was deprecated in iOS 9.0: Use -initWithConcurrencyType

You essentially will always have at least 1 context with NSMainQueueConcurrencyType and many contexts with NSPrivateQueueConcurrencyType. NSPrivateQueueConcurrencyType is used typically for saving or fetching things to core data in the background (like if attempting to sync records with a Web Service).

The NSMainQueueConcurrencyType creates a context associated with the main queue which is perfect for use with NSFetchedResultsController.

The default core data stack uses a single context with NSMainQueueConcurrencyType, but you can create a much better app by leveraging multiple NSPrivateQueueConcurrencyType to do any work that does not affect the UI.

NSURLConnection initWithRequest is deprecated

It seems that the whole NSURLConnection API has been deprecated in iOS 9. Existing apps will continue to work, but new builds (linked against iOS SDK) must use the newer NSURLSession API.

Ray Wenderlich has a good tutorial here.
Also, of course, check the official documentation.



Related Topics



Leave a reply



Submit