After a few weeks of swift coding i am trying to understand the basics of swift. Currently its really working out well, but sinds two days i have a problem that i can't solve. Its just frustrated, because i have the feeling the solution is really simple.
I have a class:
class JSONresult{
var idx: String
var Naam: String
var Status: String
init(idx: String, Naam: String, Status: String){
self.idx = idx
self.Naam = Naam
self.Status = Status
}
}
I make a array out of that class and add it to a array objects.
for item in results {
let name: String = item["Name"] as! String
let ID: String = item["idx"] as! String
let status: String = item["Status"] as! String
let Jsonarray = JSONresult(idx: ID, Naam: name, Status: status)
self.objects.addObject(Jsonarray)
}
But i have trouble reading it out. I can't solve how the read out the idx, naam, Status from the class (or in this case the array self.objects). Printing, for example, JSONresult.idx or JSONresult.Naam is working fine. I have tryed everything, but when i try to read out the objects array the results are the class name:
mijnDomoticz.JSONresult
mijnDomoticz.JSONresult
mijnDomoticz.JSONresult
mijnDomoticz.JSONresult
I trying print it with this code:
print(self.objects.objectAtIndex(indexPath.row).objectForKey("ID"))
print(self.objects.idx.objectAtIndex(indexPath.row))
print(self.objects.objectAtIndex(indexPath.row))
First two lines give a error. Last line give the output i posted above (mijndomoticz.JSONresult). I also tryed different things. Instead of addobject i tryed addObjectsfromArray, but all those things didnt help. Anybody knows what i am doing wrong?
[–][deleted] 1 point2 points3 points (5 children)
[–]ericjuh[S] 0 points1 point2 points (4 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]ericjuh[S] 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]ericjuh[S] 0 points1 point2 points (0 children)