[英]Swift 3 Core Data - init(context:) is only available on iOS 10 or newer
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? 我收到错误“init(context :)仅在iOS 10中可用。我在iOS 10之前的方法中可以做什么?
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. 它在Swift 3.1下测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.