My code is as follows:
let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).managedObjectContext
let feed = Sources(context: managedObjectContext)
I am receiving the error "init(context:) is only available in iOS 10. What is the way I can do this in the pre-iOS 10 method?
Thanks!
You can use following method to compatible with all versions:
let entity = NSEntityDescription.entity(forEntityName: "YourEntityName", in: managedObjectContext)!
let feed = Source(entity: entity, insertInto: managedObjectContext)
It is tested under Swift 3.1.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.