JS to Swift
For my thesis project at Hack Reactor my group elected to build a native iPhone app using Swift. I was excited to learn Swift because I felt that learning another language and developing for a different platform would be a great way to become a better software engineer. I believe that it has and here’s why:
It deepened my understanding of pointers and memory. These concepts are largely ignored in Javascript.
It has made me painfully aware of convenient layers of abstraction in Javascript. For example, Javascript arrays can hold any type, they are by default mutable, and they automatically resize when changed and they automatically track their size. Javascript arrays certainly feel luxurious.
My understanding of object oriented programming has deepened. In Swift you actually need to declare class values as public, whereas in Javascript you merely add an underscore before values that you want the user to “accept” as private.
Thinking about the solution to a problem in language agnostic terms is valuable. Control flow and logic statements are fairly consistent across languages. Learning a new language has strengthened my basic understanding of algorithm design.
When Swift was announced last July there was a lot of excitement over the simplicity and accessibility of this new language. People felt that the learning curve for Swift would be substantially less than that of Objective C. In fact, the name “Swift” probably has more to do with increasing developer productivity than any potential performance benefits(Speed tests in fact seem to show Objective C actually performs much faster than Swift). So just how easy is it to learn Swift?
Short answer: Very.
Coming from a strong Javascript background I was excited to learn Swift because I felt that it would make me a stronger software engineer in general. I was nervous at first that the language would be difficult but I actually found the learning process to be very satisfying. Javascript can be defined as very “loosey-goosey”. Swift though follows a more rigid design philosophy. It is more abstracted than a C based language though and so it falls somewhere between C and Javascript. After only a few days the Swift syntax became familiar and I was able to solve our morning algorithm puzzles in Swift as well as Javascript.
Here are some of the big gotchas that I came across while learning Swift:
Arrays need to be filled with the same type of data.
Dictionaries are not JS Objects and need to have consistent data for all keys and consistent data for all values.
In order to perform unit testing on a class in Xcode you must declare the class and certain functions as public.
iOS Development
Swift is great and easy to learn, but an important thing to note is that learning Swift and learning iOS development are two different things entirely. Learning iOS has been a beast. I have spent hours trying to accomplish seemingly simple tasks. Some tasks, like designing the layout and appearance of the App, took far less time in xCode than it would in HTML and CSS but other tasks, like making asynchronous calls to a server, took forever to figure out. Learning iOS has been very difficult, but learning Swift has been easy and fun.