Pete On Software

RSS Feed

Archive for July, 2014

Swift – Our First iOS Application

Apple's Swift LanguageLast time, we looked at creating functions in Swift. This time, we are going to stop being theoretical and playing in the playground and make an honest to goodness iOS application.

We won’t be getting any billion dollar valuations, but we are going to learn some fundamentals. As I thought about the best way to demonstrate all that there is to see and do when creating an iOS application, it occurred to me that a screencast was the best way to go. I hadn’t ever done one before, but why let that stop me? So, I got Camtasia for Mac, watched some tutorials, and hit record.

It is recorded in 720p HD, so you should change the quality on the video if you want to get the maximum effect. I’d welcome any feedback that you have to give, here or on the YouTube page itself.

Next time – now that we are Swift Veterans (for truth?) – I’m planning on preparing another screencast to make a more complicated iOS application that reads in a RESTful API, displays data, and allows us to interact with it.

Podcast Episode 19 – Imposter Syndrome

Imposter, shhhh, don't tellThis week, in Episode 19, I talk about Imposter Syndrome: what it is, what it means, and how to deal with it.

I can’t tell you the number of times that I’ve felt like the biggest fraud in the room and that at any moment everyone would figure it out and ask me to leave. It is absolutely the worst when I’m starting a new job or giving a talk somewhere. I figure that no one is going to allow the sham to go on and will put me out of my misery.

This isn’t an uncommon feeling, particularly in our industry. If you’ve ever felt like you aren’t qualified to do your job or that at any minute that people could find out that you have been fooling them, then this episode is for you.

Links Mentioned in this Show:
Hanselman Phony Post
Podcast Answer Man Imposter Syndrome
Imposter Syndrome @ Geek Feminisim
The Don Cheadle Line that I referenced (48 seconds in)
Hacker News Tools of the Trade: 2014 Edition
A better way to ask “how much would it cost to develop this app?”

You can also subscribe to the podcast at any of these places:
iTunes Link RSS Feed Listen on Stitcher
In addition, my podcast is available on DoubleTwist, Swell, and the Windows Marketplace.
Thanks to all the people who listen, and a special thanks to those who have rated me. I really appreciate it.

Listen here:

Swift – Functions

Apple's Swift LanguageIn the previous post in our series, we looked at control structures in Swift: if statements, switch statements, for loops, and while loops. Today, we are going to look at how to create functions in Swift.

In Objective-C, an instance method would be defined this way:

Many newcomers to Objective-C (myself included!) find this syntax to be very confusing. Fortunately, the Swift version of function declaration is much much simpler. Here is a simple example to add two numbers:

You can then call it like this:

The first important thing to note is that the function begins with a func keyword and its implementation body is wrapped in curly braces like C-based methods. Unlike C-based method syntax, the return type isn’t specified before the function name itself. Parameters, while in parentheses like C-based declarations, use a similar syntax to Objective-C with the name:type syntax.

As a side note, just like this Stack Overflow Answer, I’ve always thought that the difference between a function and a method was like this, “A method is on an object. A function is independent of an object. For Java, there are only methods. For C, there are only functions. For C++ it would depend on whether or not you’re in a class”. In Swift, even if a method is in a class (and Swift documentation refers to it as a “method”), it still uses the func keyword. I was thrown off by it a bit and I just wanted to point it out.

You can also accept a dynamic number of parameters in a Swift function. This is often used in string format commands or arguments to be parsed when you start an application. Here, lets just take in a dynamic number of numbers to add together.

In addition, you can also return multiple values from a function in the form of a Tuple. The declaration is very intuitive – given what we know so far. We just have to change our return type from Int or String into a custom Tuple type, in this case (String, String, String). To access each value, you just use the dot and then the index of the position in the Tuple that you want to access. See below:

The console output is then:
Swift Tuple Example

In Swift, functions are first class citizens and can be passed in as arguments, or returned as values. This can be used like the block syntax in Objective-C, or to work in Swift as a functional programming language paradigm. Here is an example of a function that returns another function, which can then be used later.

Here is an example of a function that takes another function:

Lastly, instead of a predefined function, I can also pass in an anonymous function. This allows us to get the same feature set as Objective-C’s block syntax. Assuming we still have our doSomethingToNumbers function and our ourNumberList array in scope, I could do this:

To pass in a function as a closure like that, you wrap the entire thing in curly braces, then you define the signature. Instead of using curly braces again to define the body of the function, you use the “in” keyword and define the body of your closure, like I did in the example above.

As you can see, Swift functions are simple and powerful with a syntax that is much easier to understand and read than Objective-C syntax. With very little effort, you should be able to grasp the syntax and start building reusable blocks of code. In the next post in this series, we’ll make a simple “Hello, World” application with Swift.

Podcast Episode 18 – Google I/O 2014 Recap

Google I/O 2014This week, in Episode 18, I recap the recent 2014 edition of the Google I/O conference. I run down all of the changes that are announced in “L”, as well as the changes to Chromecast and Chromebook. In addition, I cover the new products announced during IO: Google TV, Google Auto, and Google Wear.

I do contrast some of I/O against WWDC, but for the most part, the bulk of the announcements are independent. Android really wants to run on everything, while Apple seems content to run on their little sphere of the world. I suppose that the market will ultimately decide which way they prefer.

Links Mentioned in this Show:
Google Design Guide
Android TV
Interviewing.io
Google Cardboard
Listen To This Episode:

You can also subscribe to the podcast at any of these places:
iTunes Link RSS Feed Listen on Stitcher

In addition, my podcast is available on DoubleTwist, Swell, and the Windows Marketplace.

Thanks to all the people who listen, and a special thanks to those who have rated me. I really appreciate it.