在我的代码,我有NSManagedObject
以下扩展名:支持多种的iOS SDK版本的雨燕
extension NSManagedObject {
convenience init(context: NSManagedObjectContext) {
let name = self.dynamicType.entityName()
let entity = NSEntityDescription.entityForName(name, inManagedObjectContext: context)!
self.init(entity: entity, insertIntoManagedObjectContext: context)
}
}
正在工作按预期在Xcode 7/9的iOS SDK。然而,iOS的10 SDK增加了一个方法具有相同签名:
/* Returns a new object, inserted into managedObjectContext. This method is only legal to call on subclasses of NSManagedObject that represent a single entity in the model.
*/
@available(iOS 10.0, *)
public convenience init(context moc: NSManagedObjectContext)
这使编译器不开心:Initializer 'init(context:)' with Objective-C selector 'initWithContext:' conflicts with previous declaration with the same Objective-C selector
现在,我想用新的IOS 10的init(如果可用),并继续使用我的如果应用程序在iOS 9设备上运行,则为扩展名。
如何在限制现有代码中的变化的情况下实现此目标有一个很好的方法吗?我想将init
的签名保留在扩展名中。