草庐IT

detailItem

全部标签

ios - 需要修复代码 "Property ' managedObjectContext' not found on object of type 'id' 中的错误。”

我正在为我的类(class)编写这段代码,但我卡住了,错误是“在‘id’类型的对象上找不到属性‘managedObjectContext’它落在这行代码上:if(![self.detailItem.managedObjectContextsave:&error])我知道在代码的前面我将newDetailItem设置为类型id?:-(void)setDetailItem:(id)newDetailItem{if(_detailItem!=newDetailItem){_detailItem=newDetailItem;//Updatetheview.[selfconfigureView]

ios - 带有 cast 的快速可选链接

下面的代码突出了我在将可选链接和强制转换与Apple的swift语言结合时遇到的问题importFoundationimportCoreDataclassMyExample{vardetailItem:NSManagedObject?funcexample(){//IntheactualimplementationitisassignedtoaUITableViewCelltextLabel.textwiththesameresult.letname:String=self.detailItem?.valueForKey("name")asString}}以上结果:'AnyObject