Create an Array of AnyObject, you have to keep in mind that to access the index subscript you must have an array
var chartData: Array = 
Create an instance of AppDelegate and NSManagedObjectContext
let appDel: AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
let context: NSManagedObjectContext = appDel.managedObjectContext!
Create a fetch request an execute it
var fetchRequest = NSFetchRequest(entityName: “ActivityEntity”)
chartData = context.executeFetchRequest(fetchRequest, error: nil) as [ActivityEntity]
To access the attributes of the entity, create an instance of NSManagedObject and use valueForKeyPath(“Attribute’s name”)
var data: NSManagedObject = chartData[Int(index)] as NSManagedObject
var percentage = data.valueForKeyPath(“activityPercentage”) as Int
Tags: core data, swift
Sometimes when creating a variable, a couple of alerts warnings…
first of, go to terminal and enable root type in,…
I wanted to have a swift class file that contains…
Your email address will not be published.
Notify me of follow-up comments by email.
Notify me of new posts by email.