I have been trying so hard to loop in NSArray parse it and then add it to NSMutableArray. the issue is not with parsing i wanted to loop over the whole NSArray.
Here is my code:
if let dictionarys : NSArray = dictionary.valueForKey("response") as? NSArray {
var categoryNum = 0
var currency = "0"
if let category: NSArray = dictionarys.valueForKey("category") as? NSArray {
if let catId = category.valueForKey("categoryID") as? NSArray {
categoryNum = catId[0] as! Int
}
}
if let currency1: NSArray = dictionarys.valueForKey("currency") as? NSArray {
if let currency2 = currency1[0] as? String {
currency = currency2
}
}
serviceObject = ServicesObject(categoryId: categoryNum,currency: currency)
CategoryItems.addObject(serviceObject)
}
self.tableView.reloadData()
i want to do something like this :
for (var i = 0;i<dictionarys.count ; i++){
var categoryNum = 0
var currency = "0"
if let category: NSArray = dictionarys.valueForKey("category") as? NSArray {
if let catId = category.valueForKey("categoryID") as? NSArray {
categoryNum = catId[0] as! Int
}
}
if let currency1: NSArray = dictionarys.valueForKey("currency") as? NSArray {
if let currency2 = currency1[0] as? String {
currency = currency2
}
}
serviceObject = ServicesObject(categoryId: categoryNum,currency: currency)
CategoryItems.addObject(serviceObject)
}
a sample of what I'm trying to parse i did : print(dictionarys)
(
{
category = {
category = "<null>";
categoryID = 66;
};
currency = 2;
},{
category = {
category = "<null>";
categoryID = 66;
};
currency = 2;
},{
category = {
category = "<null>";
categoryID = 66;
};
currency = 2;
}
)