1
這個Objective-C協議用於在Swift 1.1中工作,但現在在Swift 1.2中出現錯誤。使用getter的Objective-C協議的Swift 1.2錯誤
Objective-C的協議剝離下來到一個問題的性質:
@protocol ISomePlugin <NSObject>
@property (readonly, getter=getObjects) NSArray * objects;
@end
class SomePlugin: NSObject, ISomePlugin {
var objects: [AnyObject]! = nil
func getObjects() -> [AnyObject]! {
objects = ["Hello", "World"];
return objects;
}
}
以下是雨燕1.2的錯誤:
Plugin.swift:4:1: error: type 'SomePlugin' does not conform to protocol 'ISomePlugin'
class SomePlugin: NSObject, ISomePlugin {
^
__ObjC.ISomePlugin:2:13: note: protocol requires property 'objects' with type '[AnyObject]!'
@objc var objects: [AnyObject]! { get }
^
Plugin.swift:6:9: note: Objective-C method 'objects' provided by getter for 'objects' does not match the requirement's selector ('getObjects')
var objects: [AnyObject]! = nil
^
如果我改變協議(這我真的不能,因爲它做的來自第三方)到以下代碼編譯罰款。
// Plugin workaround
@protocol ISomePlugin <NSObject>
@property (readonly) NSArray * objects;
- (NSArray *) getObjects;
@end
在此先感謝。