2016-12-12 6 views
0

SENARIOObjective-C + Swift with CoreData - 'EntityName'の値型を 'EntityName'に割り当てることはできません。

私はObjective-Cのプロジェクトにスウィフト3をマージしていたプロジェクトに取り組んでいます。プロジェクトでCoreDataが使用されていて、Objective-CでAppDelegate "EntityName"の型を宣言し、Swift 3クラスに割り当てようとしましたが、ビルドエラーが発生しました。 "EntityNameの型を 'EntityName' ''


CODE

AppDelegate.h

// Declaration 
@property (strong, nonatomic) EntityName * entity; 

スウィフトクラス

// Array Property 
var entityList = [EntityName]() 

... 

// Assignment 
let appDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate 
appDelegate.entity = self.entityList[indexPath.row] // throws error 

Iは

1を試したどのようなエラー

can not assign type of 'EntityName' to type 'EntityName!' 

appDelegate.entity = self.entityList[indexPath.row] as EntityName! // throws error 

ERROR

can not assign type of 'EntityName!' to type 'EntityName!' 

2)

appDelegate.entity = self.entityList[indexPath.row] as EntityName? // throws error 

ERROR

can not assign type of 'EntityName?' to type 'EntityName!' 

QUESTION

どのように私はこれを是正し、私の一日に乗るのですか?

答えて

0

いくつかの試行錯誤の末、私はこの問題を修正しました。私の場合、私は次の手順を実行しなければならなかった:

1)ナビゲートへとCoreDataのモデルを選択...右側に

AppName.xcdatamodeld

2)、ファイルインスペクタを表示中...

enter image description here

3)コード生成セクション、Objective-C言語を選択...

enter image description here


マイ.xcdatamodeldファイルのコード生成は、スウィフトに設定しました。私は古い格言を信じています。「SwiftがObjective-CよりもObjective-Cに準拠する方が簡単です。

関連する問題