Swift challenge 10: Remote JSON

This was really more programming than I’ve done before. Because it doesn’t even produce a final result, just something in the log. So what does this even mean?

What is JSON?

JSON is a method to structure data and it looks like this:

{"title":"headline 1","body":"This is the content"}

What is remote JSON?

Remote JSON is when the content is from an external source rather than from within the app, for example in a text file.

What have I actually achieved?

I wanted to use the data from my personal project and see how it would work in an app.

Result

This is the source: http://moshpitandcode.com/gigs/bands/1?json and below is what it produced

2016–03–02 21:56:08.825 Challenge 10: Remote JSON[33043:9706874] Response code: 200
{
band = {
“created_at” = “2015–10–26 21:28:43”;
gigs = (
{
“created_at” = “2015–11–19 21:08:05”;
“end_date” = “2013–06–19 00:00:00”;
“from_date” = “2013–06–19 00:00:00”;
id = 109;
name = “30 seconds to mars”;
pivot = {
“band_id” = 1;
“gig_id” = 109;
};
type = concert;
“updated_at” = “2015–11–19 21:08:05”;
“venue_id” = 16;
}
);
id = 1;
name = “30 seconds to mars”;
“updated_at” = “2015–10–26 21:28:43”;
};
}

This was technically challenging because so many techniques need to be involved + I would not recommend getting the result from http. Even apple requires https as a source. You can however override it in the info.plist.

The code to download data is here:

For the next remote JSON thing I will probably download a CocoaPod for it. Because that’s a lot of code and not very elegant.

Here is the complete code

This is the source I used, which my whole code is written on.