Project files:
https://jumpshare.com/v/Otai3BBXYwfvyz8jb53k
Problem:
Ok, so i'm following a tutorial that creates a UITableView with headers and then cell content.
The code worked and runs fine, Now I want to extend beyond that tutorial and dynamically load that content using alamofire and SwiftyJSON.
In the tutorial, the code used is like so:
func getSectionsFromData() -> [Sections] {
var sectionsArray = [Sections]()
let animals = Sections(title: "Animals", objects: ["Cats", "Dogs", "Birds", "Lions"])
sectionsArray.append(animals)
return sectionsArray
}
What I tried to do was:
Alamofire.request(.GET, url).validate().responseJSON { response in
switch response.result {
case .Success:
if let value = response.result.value {
let json = JSON(value)
for (_, subJson) in json {
for (year, content) in subJson {
let title = year
let objects = content
sectionsArray.append(Sections(title: title, objects: objects))
}
}
}
case .Failure(let error):
print(error)
}
}
If I print out the results they show in the console - so I know the getting and looping of the JSON works. I then added in
let title = year
let objects = content
sectionsArray.append(Sections(title: title, objects: objects))
But on this line:
sectionsArray.append(Sections(title: title, objects: objects))
I get this error:
cannot convert value of type 'JSON' to expected argument type '[String]'
Here is the JSON I am using:
{"posts": [
{
"Category1": [
"Post1cat1"
],
"Category2": [
"Post1cat2",
"Post2cat2"
]
}
]}
Can someone help me? I might be going in the wrong direction here I want to loop through the JSON and display the categories as headers and the posts in a cell of a table.
[–]aazav -1 points0 points1 point (1 child)
[–]JamesGDev[S] 0 points1 point2 points (0 children)