Tuesday, January 5, 2016

Day 52

Intermediate Swift and SwiftySinglyLists


One of the annoying things about Swift coming from Javascript is how safely your code has to be in Swift for it to be executed. For example, Swift brings up a new idea of optionals. In Swift, nil or null is a very bad thing. Optionals help with that: when you declare a variable as an optional (by having a '?' sign) you're stating that "hey, there might be a value for this variable but there might not be". This allows the program to run knowing that if nothing is in it, it will be ok because the variable expects that result. The annoying part is that when you have an optional..you can't really do anything with it. You have to unwrap it by declaring, which will return it back to whatever type it is supposed to be.

New things that I learned were structs and enumerations. Enumerations are data types with its values being related in some way. Think of a dropdown list of items. Structs are another data types that holds attributes. The most important distinction with structs and enum are that, when used, a copy of the data is being manipulated instead of the actual data. Structs are primarily used for things that are not too complicated and its attributes will not be changed. For all other data type manipulation, use class.

The assignments today were pretty hard to follow since we re-did the Singly Linked Lists in Swift. I'm not too well-versed in SLL's yet and although I can follow the code and what everything is doing, I have a hard time writing the correct code for the assignments.

No comments:

Post a Comment