LoginSignup
16
18

More than 5 years have passed since last update.

Swift + Cocoa Bindingで気をつけること

Posted at

ObjCでCocoa Bindingを使っているサンプルをSwiftで書き直して実行するとこんなエラーがでました。

Cannot find object class with name ParsonModel

どうやらコントローラにバインドしたモデルクラスが見つからないようです。

原因

Swiftではシンボル名がマングルされるので、クラス名だけでは名前を特定できない。

対策

モジュール名.クラス名 というように指定する必要があります。

こちらのサンプルをSwiftで書き換えていきます。
Quick Start for Collection View - Mac Developer Library

ほとんど何も考えないで書き換えられますが、
Make the Array Controller and the Array でクラス名を指定する時だけ
"モジュール名.PersonModel" とする必要があります。

またはクラスに(@objc)を付けておけば クラス名 だけでよくなります。

@objc(PersonModel)
class PersonModel : NSObject {
...
}

参考

Swift – “Cannot find object class with name” - stackoverflow

16
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
18