为什么我不能继承NSCell的任何子类?
我想继承MyButtonCell
,CustomButtonCell: NSButtonCell
。含义
class MyCustomButtonCell: MyButtonCell { }
总是给我以下错误:
<unknown>:0: error: declaration has a different @objc name from the declaration it overrides ('initTextCell:' vs. 'initWithTextCell:')
Custom_Controls.MyButtonCell:9:24: note: overridden declaration is here
@objc @objc override init(textCell aString: String)
^
<unknown>:0: error: declaration has a different @objc name from the declaration it overrides ('initImageCell:' vs. 'initWithImageCell:')
Custom_Controls.MyButtonCell:10:24: note: overridden declaration is here
@objc @objc override init(imageCell image: NSImage?)
^
重现我的问题的简单步骤:
打开终端
输入:swift
(如果你有最新的Xcode 6.3.1)
当你到达时,
Welcome to Swift version 1.2. Type :help for assistance.
键入以下内容:
1> import AppKit
2> class Foo : NSCell {}
3> class Bar : Foo {}
declaration has a different @objc name from the declaration it overrides ('initTextCell:' vs. 'initWithTextCell:')__lldb_expr_9.Foo:3:24: note: overridden declaration is here @objc @objc override init(textCell aString: String) ^ declaration has a different @objc name from the declaration it overrides ('initImageCell:' vs. 'initWithImageCell:')__lldb_expr_9.Foo:4:24: note: overridden declaration is here @objc @objc override init(imageCell image: NSImage?) ^
为什么呢?有没有解决这个问题的方法?
仅供参考:Swift 1.1没有这个问题!