2

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?)
                       ^

私の問題を再現する簡単な手順:

  1. ターミナルを開く

  2. タイプ: swift(最新の Xcode 6.3.1 を使用している場合)

  3. あなたが取得するとき、

    Welcome to Swift version 1.2. Type :help for assistance.

次のように入力します。

1> import AppKit
2> class Foo : NSCell {}
3> class Bar : Foo {} 
  1. 次のエラーが表示されます。

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 にはこの問題はありませんでした。

4

1 に答える 1