简体   繁体   English

Swift 3核心数据 - init(context :)仅适用于iOS 10或更高版本

[英]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.

相关问题 Swift 3-“ NSPersistentContainer仅在ios 10和更高版本上可用” - Swift 3 - “NSPersistentContainer is only available on ios 10 and newer” self.locationManager.requestAlwaysAuthorization()仅在iOS 8.0或更高版本上可用-Swift - self.locationManager.requestAlwaysAuthorization() is only available on iOS 8.0 or newer - Swift XCUIApplication仅适用于iOS 9.0或更高版本的swift3 - XCUIApplication is only available on iOS 9.0 or newer, swift3 Swift 编译器错误 (Xcode):Concurrency is only available in iOS 15.0.0 or newer - Swift Compiler Error (Xcode): Concurrency is only available in iOS 15.0.0 or newer 无法将解析的数据保存到URLSession到Core Data上下文中(iOS 10,Swift 3) - Can't save parsed data into URLSession to Core Data context (iOS 10, Swift 3) Xcode 10'frame'仅适用于iOS 12.0或更新的编译错误iOS 12 beta - Xcode 10 'frame' is only available on iOS 12.0 or newer compilation error iOS 12 beta 'LABiometryType'仅适用于iOS 11.0.1或更高版本 - 'LABiometryType' is only available on iOS 11.0.1 or newer “ AppDelegate”仅在iOS 10.0或更高版本上可用 - 'AppDelegate' is only available on iOS 10.0 or newer Searchcontroller仅在iOS 11或更高版本上可用 - Searchcontroller only available on iOS 11 or newer centerXAnchor仅在iOS 9.0或更高版本中可用? - centerXAnchor is only available in iOS 9.0 or newer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM