以下のようにSwift側からObjective-Cベースのアクセサメソッドを呼ぼうとすると
コンパイルエラーになります。
Swift側で何か処理をしなくてはならないのでしょうか?それとも何か間違っているのでしょうか?
2015/06/28 追記
使用しているライブラリはCocoaPodsから導入した、Objective-CベースのNLCoreDataというものです。この中でNSManagedObjectやNSManagedObjectContextなどを拡張?してentityNameなどのプロパティを追加しています。
2015/06/28 追記2
NLCoreDataライブラリ内のentityNameはメソッドでゲッターのような物でした。Objective-C側でプロパティに対してアクセサが自動生成されるのであれば,swiftからsetプロパティ名が使用できるのではないかと思ったのですが,そもそもプロパティではありませんでした。その他、インスタンスプロパティであるmodelNameなどはSwift側からインスタンス.プロパティ名という書式でのアクセスができました。
class testRecordViewController: UIViewController { NSManagedObject.setEntityName(myEntity) //エラー 'NSManagedObject.Type' does not have a member named 'setEntityName' (NLCoreData.shared()).setModelName("aiueo") //エラー 'NLCoreData' does not have a member named 'setModelName' ...省略 }
ここでsetしようとしてるプロパティは,NLCoreDataライブラリの中では以下のように宣言されています。
lang
1// ヘッダーファイル 2/** 3 Model name. Set this before use, typically in application:didFinishLaunchingWithOptions: 4 If your data model is named MyDataModel.xcdatamodeld, set modelName to @"MyDataModel". 5 This is optional. If not explicitly set, NLCoreData uses CFBundleName for the main bundle. 6 E.g., if the app is named "MyApp", the model should be named "MyApp". 7 */ 8@property (strong, nonatomic) NSString* modelName;
lang
1// ソースファイル 2#pragma mark - Properties 3 4- (NSString *)modelName 5{ 6 if (_modelName) 7 return _modelName; 8 9 _modelName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]; 10 11 return _modelName; 12}
よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー