Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
José Manuel Martínez López
18,133 PointsHow can i get information from a tableView and do math with it?
First i tried to get the information from the attribute of my entity and i did but i get an array i can't work with it. So i remembered i had the information in the tableView. This is my code:
var error : NSError?
let appDel: AppDelegate=UIApplication.sharedApplication().delegate as AppDelegate
let context: NSManagedObjectContext=appDel.managedObjectContext!
var request=NSFetchRequest(entityName: "Ingresos")
request.returnsObjectsAsFaults=false
myData=context.executeFetchRequest(request, error: &error)!
//var sData:AnyObject
var sData:AnyObject
var c1:String
var c2:Double
var total:Double
for i in myData{
sData=i.valueForKey("dinero")!
c1=sData as String
c2=(c1 as NSString).doubleValue
}
1 Answer
José Manuel Martínez López
18,133 PointsWell i didn´t find how to get the information from my tableView but i did found how to get the information from my core data and then work with it:
var data:Array<AnyObject>=[] var dConv:Array<Double>=[] var c1:String var c2:Double var sData:AnyObject?
for i in array{
data.append(i.valueForKey("dinero")!)
}
for i in data{
sData=i
c1=sData as String
c2=(c1 as NSString).doubleValue
dConv.append(c2)
}
for i in dConv{
sum2=i+sum2
}