0

In Swift 2, I had used the following code:

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

Now, using Xcode 8.0 beta (8S128d) and Swift 3, Xcode tell me:

Value of type 'NSFetchRequestResult' has no member 'value'

How can fix this error?

Thank you

Ziggy
  • 121
  • 1
  • 9
  • See [What's new in core data](https://developer.apple.com/library/prerelease/content/releasenotes/General/WhatNewCoreData2016/ReleaseNotes.html) as well as [Q&A: Swift 3, NSFetchRequest](http://stackoverflow.com/questions/37810967/swift-3-nsfetchrequest). I believe this thread is possibly a duplicate candidate for the latter link. – dfrib Jul 22 '16 at 07:48
  • Sorry dfri, I read that thread many times during my search for candidate answer. But in my opinion, Deniss asked about different issue. Both thread ask about NSFetchRequest but in my thread I don't understand how can use value(forKeyPath.... in swift 3. – Ziggy Jul 22 '16 at 08:05
  • I believe that you're looking for `func valueForKeyPath(_ keyPath: String) -> AnyObject?` blueprinted in [the `NSKeyValueCoding` protocol](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSKeyValueCoding_Protocol/#//apple_ref/occ/instm/NSObject/valueForKey:). – dfrib Jul 22 '16 at 08:14

1 Answers1

2

I solved on different way.

Instead of using loop with enumerated(), I created an array of objects and I access to XXX attribute by:

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