2016-07-22 60 views
0

在夫特2,我曾使用以下代碼:迅速3,NSFetchRequestResult沒有成員值

for (_, value) in self.frc.fetchedObjects!.enumerated() { 
    if (value.value(forKeyPath: "name_of_field_of_entity_name") as? String == "S") { 
    ... 
    } 
} 

現在,使用的Xcode 8.0β(8S128d)和SWIFT 3時,Xcode告訴我:

值類型的「NSFetchRequestResult」沒有成員「價值」

如何解決這個問題?

謝謝

+0

參見[什麼在覈心數據的新(https://developer.apple。 com/library/prerelease/content/releasenotes/General/WhatNewCoreData2016/ReleaseNotes.html)以及[問與答:Swift 3,NSFetchRequest](http://stackoverflow.com/questions/37810967/swift-3-nsfetchrequest)。我相信這個帖子可能是後一個鏈接的重複候選人。 – dfri

+0

對不起,在我搜索候選答案的過程中,我多次閱讀該帖子。但在我看來,Deniss詢問了不同的問題。這兩個線程詢問有關NSFetchRequest,但在我的線程中,我不明白如何使用值(forKeyPath ....在swift 3. – Ziggy

+0

我相信你正在尋找'func valueForKeyPath(_ keyPath:String) - > AnyObject? '在[NSKeyValueCoding'協議]中藍圖(https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSKeyValueCoding_Protocol/#//apple_ref/occ/instm/NSObject/valueForKey: )。 – dfri

回答

2

我解決了不同的方式。

代替使用環與列舉的(),I創建的對象的陣列,並且我通過訪問XXX屬性:

let xxx = self.frc.fetchedObjects as! [XXX] 
for i in 0..<(xxx.count) { 
    print(xxx[i].attribute_of_XXX) 
}