0

I need to get both the attribute name and the value for the attribute when I'm reading from my core data, is there any easy way of doing this?

I've been trying to retrieve the first element in my object model as a Dictionary, but that gives me an error saying:

fatal error: NSArray element failed to match the Swift Array Element type

My code looks like this:

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

    let fetchReq = NSFetchRequest(entityName: "ActiveIndexes")
    fetchReq.resultType = NSFetchRequestResultType.DictionaryResultType

    receivedList = context.executeFetchRequest(fetchReq, error: nil) as! [ActiveIndexes]

    println(receivedList[0])

Any suggestions would be appreciated.

1

1 Answer 1

1

NSManagedObjects have a rich API for introspection.

let activeIndex = retrievedList[0]
for (key, value) in activeIndex.entity.attributesByName {
    println("\(key) : \(activeIndex.valueForKey(key as NSString))")
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.