我有一個混合的Obj-C - Swift應用程序。
我的定製的OBJ-C MapViewController
具有下面的頭文件中,其中Item
是寫在夫特自定義類:Swift:「無法賦值類型'Item!'的值鍵入'Item!'
@class Item;
@interface MapViewController : UIViewController
@property (nonatomic, strong) Item *item;
@end
的SEGUE到MapViewController
與使用
self.performSegueWithIdentifier(kMapSegueId, sender: item)
一個
Item
對象
item
發起
此調用,其中item
以sender
發送:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == kMapSegueId {
let mapViewController = segue.destinationViewController as! MapViewController
mapViewController.item = sender as! Item! // This gives the error
}
}
然而,分配到MapViewController
的財產item
給人的編譯器錯誤
無法指定類型的值「項目!」鍵入'Item!'
我該如何避免這種奇怪的錯誤?
'as!'已經解開了可選項,'Item'後面的感嘆號沒有意義,很可能是問題。 – vadian
@vadian:我之前試過這個,但沒有Item後面的感嘆號,我得到錯誤「無法指定'Item'的值來鍵入'Item!'」 –
Item'是否有'@ objc'屬性? –