Get values from fields of a Nsarray with Coredata content

Asked

Viewed 36 times

0

I have a table on coredata with some fields, I can get the size of these values but I need the values of each field, I have this code:

var request:NSFetchRequest = NSFetchRequest(entityName: "Radar") //my table in coredata

let appDelegate:AppDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)
let context:NSManagedObjectContext = appDelegate.managedObjectContext!

request.returnsObjectsAsFaults = false

var results:NSArray = context.executeFetchRequest(request, error: nil)!

println(results.count) //this is the count that i can do

But I need more, Radar has these fields: Desc, Lat, Long and I need your values to create a Annotation.

1 answer

1


I’ve got it figured out for whoever needs it here:

if results.count > 0
{
    for result in results
    {
         if let r = result as? Radar{
             //now you can access the properties of Radar in r
             println(r.descr)
         } else{
             println("Could not cast fetch result to Radar")
         }
    }   
}
  • you can accept your own answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.