We covered a few different topics these two classes so I thought it would be helpful to split it up.
Closures: Essentially a lazy way of writing functions. These are actually pretty cool because what would usually take about four or five lines of code can be done in one or two. A closure essentially allows you to add or overwrite functionality in some built in commands. The example we did in class was with an array and how you can easily write a sort algorithm or a min/max function.
You can read more about closures here
Async: This is a common concept when dealing with user interfaces and functions that take some time to respond. For the most part computers handle actions at unnoticeably fast speeds but a problem comes in when we want to send and get data over the internet. Now your program is open to a boatload of errors that could be caused by things out of your control, like internet connection and speed. So async to the rescue! Writing code that supports asynchronous functions allows us to start a connection to a remote server, but then continue to do other things while we wait for the response. Without this support our app would wait for the response, and if there’s a bad connection could cause it to crash. We used AlamoFire to make our lives easier with a bunch of cool networking functions.
JSON: All transmissions between web applications use json as a standardized format. It’s clear, easy to understand, and pretty much globally accepted. Even I use it at my workplace. Luckily Tony (the instructor) has our back and introduced us to a cool library called SwiftyJson which made processing and sending data in json format a piece of cake. It was actually weird how easy everything was, it just magically worked. As a fun tidbit he showed us how to process json in SWIFT 1, which for the same functionality, took about twice the amount of code. Thank god this class started as SWIFT 2 came out.
Putting all our knowledge together, we talked about making REST calls to a weather API. Essentially just giving it a location and getting back the temperatures for that day or week. We’ll continue to work on the weather app next week, stay tuned!
Take BrainStation’s Part-Time iOS Development course, apply here!