30 days with swift — Day 02 — Hitting the gas!

Guilherme Akio Sakae
3 min readMar 3, 2015

Missed the last day post, check here:

Hitting the gas!

Today was very productive, although the content weren’t very challenging I’m very excited, the course was functions and optionals. Swift have a lot to offer regarding these new topics, now functions are very easy and looks more like the new programming language functions, you can say goodbye to the verbose functions on objective-c , forgot creating functions like:

-(void) doSomethingAmazing: (NSString *)when toPerson: (NSString *)personName andSendMessage: (NSString *)message {…}

Now just do:

func doSomethingAmazing (#when : String, #personName : String, #message : String) {…}

I’m not going to explain the function declaration because it’s very flexible but looks quite better, right? Swift provides alternate methods to simulate the same behaviour, now you can chose between very short or very verbose, you can name the parameters or don’t you’re free to choose, this is quite new concept for apple, right? (just kidding ☺)

Optionals are this new concept and came to add more “class” to the language, now instead of always return something like:

func search(something : String) -> Bool { if found { return true} else { return false}}

You can do:

func search(something : String) -> Bool? { if found { return true} else { return nil }}

I know this example aren’t the best but you get the idea, optionals just make the return of the function… well… optional. You can also use the new if form: if-let to complement this new concept, basically is just a new way to interact with the optional return, works like this (using the optional function above):

if let found = search(“pizza”) { println(“Found my pizza!”) }

The if statement above, check the return, take care if the function returns nil and associate the return to the found variable, the found variable is available inside the if context. Of course you can find a better explanation in the treehouse course.

Day Highlights

  • Today I tried to use the 1,5x speed on videos to save time, worked very well but sometimes I had to stop the video and read the code again to fully understand the topic, probably I won’t do that anymore.
  • String interpolation: such a powerful tool to use, I can see lot’s and lot’s of applications for this, definitely something to use every day.
  • Function declaration: opens lots of new possibilities, now is so easy and faster to understand and write amazing functions declarations.
  • A show to keep the users engaged, they hit at the bulls eye with this. After you finish a course sometimes they show a secret video with a side story, like a short film divided in god’s know how many parts. I’m anxious to discover the outcome of the story.

Day Two Conclusion

Step after step, I read somewhere:

“You don’t need to see the whole path, you just need to know where you want to go and see 15 feet ahead” By someone Adapted by Me

That’s sums up exactly my plan, I still haven’t wrote a single line of code inside xCode to build a app, but I trust treehouse and I trust the track organization, I also believe that learning the basics and build a great foundation is better on the long run.

Well that’s all folks!

--

--