Living in the Fastlane – Deploying 100 Apps to the App Store at Victorious

If you need to submit more that one app to App Store or Google Play store, this talk is for you! Here is how we automated our App Deployment Pipeline. We can now submit ~100 apps to the App Store at Victorious with a single command. You’ll learn how to use Fastlane so you can use it for your needs too.

Presented at the CocoaHeads Los Angeles meetup
Here is a video recording and slides

Enjoy,
Alex

Interview at Swift Coders Podcast

We’re big proponents of Swift, Apple’s new programing language at The Right Balance. It’s exciting to see the Swift community evolving. It was great to speak at the opening podcast dedicated to Swift Development called Swift Coders. Kudos to Garric Nahapetian for putting it together.

Check out the first episode here, we hope that you really like it.

Equality Operators in Swift: Double equal vs Tripe equal and how to define even your own Quadruple Equal operator

Photo by ssoosay

Yes, a quadruple operator. Bare with me, we’ll get there by the end of this post. In order to figure out how equivalence operators work, let’s start with a simple example:

Double equal

A double equal operator (aka ==) compares values. Let’s look at the simple example below:

The left-hand side and the right-hand side are different objects in all three cases. Swift compares basic types with no problem. Let’s see how Swift is doing with our custom octocat classes:

Error! Swift doesn’t know how to compare octocats. C’mon Swift! It’s not that hard, all you need is to compare the number of legs. Although it seems obvious for the author of this code, Swift doesn’t know how to compare custom objects. Every custom object has a meaning. It is pretty reasonable to push the responsibility of defining equivalence to the author. In order to do that, we need to define the equivalence operator for the Octocat class. All you need to do is to return true or false depending whether the left-hand side is equal to the right-hand side. Note that the equivalence operator is redefined outside of the class. But the Octocat type is specified inside parameters.

Now Swift is all happy and our octocats are indeed equal.

Triple equal

The triple equal (aka ===) operator compares identity. If the variable on the left points to the same exact object that the variable on the right, then it returns true. It returns false otherwise. Here is the example:

The red_skate variable and the same_red_skate variable point to the same exact instance of the Skateboard class. That’s why our tripe equal operator returns us true. The variable blue_skate on the other hand points to a different instance than what the red_skate variable points to. Therefore, the triple equal operator returns us false in the second case.

Custom operators

But wait, but there is more. Just to make things more fun, let’s introduce a quadruple equal operator for our Octocat class. Why not? It turns out that you can introduce pretty much any custom operator in Swift pretty easily. It’s a two step process. First, you’ll need to define a new operator. Be careful, it defines this new operator globally:

Then, you’ll need to implement it. Our quadruple equal operator makes absolutely sure that Octocats are the same. It compares the number of legs and the kind or an Octocat :-)

Now that we have it, let’s use it:

Recap

Swift has two major mechanisms for comparing objects. The equality operator and the identity operator. The equality operator compares values. The identity operator checks whether variables point to the same instance. Swift provides us with a way of defining custom operators. I can see it being useful in certain cases but you can easily take it too far. Before defining a new custom operator, ask yourself whether you can accomplish the same goal with existing operators.

Cheers,
Alex

Data Types in Swift

Photo by yukop

I’m currently teaching a mobile development course at GA. I’ll be sharing my swift lessons one by one. Lesson 1: Data Types. After reading this blog post you’ll be able to learn and use the basic data types in Swift. I’m going to briefly introduce a data type. Then I’ll show the syntax for creating it and what you can do with it.

Ready, get set, go!

String

The String datatype is used for storing and manipulating text. You start defining a string by using a double quotes symbol following by your text. Finish defining your string by using a second double quotes symbol.

Boolean

A boolean can be either true or false. It’s useful in conditions inside control flow statements like if. It also helps with checking whether a certain condition is met.

Range

The Range data type is used to define a range of values. It’s very handy to define long sequences.

Integer

An integer describes a whole number without a decimal point. It’s useful for performing any sort of math on whole numbers.

Double / Float

Doubles and Floats are used for numbers with precision. A double is twice as precise as a float.

Array

Array is a zero indexed, ordered collection of elements. Arrays come in handy when you need to store and operate on a collection of elements.

Dictionary

A dictionary is a collection of key value pairs. A value is stored and retrieved from a dictionary by it’s key. Dictionaries are useful for managing different sets of data. For example keeping a track of heroes and their superpowers 😉

Feel free to play with this code in the playgrounds. Every data type has a lot more useful methods on it.

Enjoy,

Alex

Running iOS tests on Travis CI

Why

Did you ever ship buggy code in production ? If it is the case, you may consider setting up a CI server.

What

CI stands for continuous integration. CI Server is a machine that watches your main branch and runs your tests every time there are new commits. It ensures that you product is ready to ship from your main branch at any point in time.

How

Setting up and especially maintaining a CI server is pain in the neck. That’s why I prefer to use a CI service instead of hosting a server in house. They scale it, they maintain it, all I do is focus on development.

Setup

Note: The following tutorial works for Cedar testing framework as well as XCTest. Tests should be set up as a test target (not a separate app).

1. Sign up for an account with Travis CI.

  • Sign up here for a free account if your project is Open Source and it’s public.
  • Sign up here is your project is private.

2. Enable the app.

Sign into your account on Travis CI. Click on your profile on the top right and choose accounts. Choose the repo that you want to test and flip the switch to on.

3. Make sure that your scheme is shared.

Open up your project in XCode. Go to Product->Scheme->Manage Schemes. Select the Target that you use for testing and check the Shared checkbox.

Shared scheme in Xcode

4. Create .travis.yml file

.travis.yml is the configuration file for your build on Travis CI. Here is the minimal .travis.yml file.  Replace MyAwesomeApp with your app name and save it in the root of your project.

5. Commit everything, push it up to github and check out you triggered build.

Cheers,

Alex

What’s next

We covered a lot of stuff. We set up the computer for local development. We created a web application and deployed it to a server. Great job!

Keep in mind, everything we’ve learned is just a tip of the iceberg. Each topic is probably worth a book of it’s own. The great thing about Software Engineering is that there is always a way to get better. Next, try to create your app and always keep learning. Keep an eye on new frameworks, libraries, languages etc.

Sign up for my Newsletter. I will be updating it with new techniques, development tools and everything you need to know to program better. Just enter your name and your email below. Let’s keep in touch.

Cheers,
Alex

Day 7: Deployment

deployment
Photo by jon_a_ross

What is deployment?

Deployment makes our application available for use. For a web application it means putting it on the Internet in most cases. This is exactly what we’re going to do in this chapter. In order to put our application on the Internet, we need a server. A server is a computer which has an access to the Internet. When we run bundle exec rails server command and go to http://localhost:3000, our laptop is the server. It is ok for your own use. In order to make it available for everyone, we need to upload our app to a server and run it there. The server will have a URL assigned to it, so everyone can access it.

Setting up Heroku

We’re going to use a service called Heroku. Here are 3 reasons why:

  1. It’s free for our small app
  2. It’s easy to setup and deploy to it.
  3. They provide you with both: a server and a URL.

Let’s set it up, it’s really easy.

Sign up for Heroku account

Open up your browser, go to http://heroku.com/signup and sign up for an account.

Install heroku-toolbelt

Go to the terminal and install heroku-toolbelt. It’s a set of command line tools that we will use to deploy to Heroku

Authenticate with heroku 

Go back to the terminal and run

It will ask you for your email and password from your account. Type it in (don’t copy and paste). It will also ask you whether you want to upload a SSH key. Do it, it will make it easier to deploy. If you already have existing keys it will ask you which one you want to upload. If you don’t have one, it will generate a new key for you.

Install heroku-push plugin

It will allow us to push our app straight from our laptop. Go back to the terminal and run this command:

Push to Heroku

We’ve created an account and installed heroku command line tools on our local machine. Now it’s time to deploy our todo application to Heroku.

First, let’s create an app on heroku. Go to your terminal. Navigate to todo project directory and run this:

heroku_app_name_and_url

Notice that it gave us the app name and the URL. App name is random for everyone. My app name is “still-taiga-7739”, your name will be different. Remember the app name. Put your app name in place of your_app_name variable for the next set of commands.

Next, add PostgreSQL database to you app. Don’t forget to use your app name instead of your_app_name variable.

Now it’s time to push our app to Heroku. Ready ? Let’s do it!

It might take a while to upload code and build an application. After it’s done, let’s run our migrations for the newly deployed app.

That’s it! Remember the URL from heroku create command ? Go to your browser, navigate to that URL. You new shiny todo app should be ready to use.

todo_app_deployed_on_heroku

What happened here

Now you understand what it takes to put your app on the Internet. Not only you can deploy your todo app. You can deploy pretty much any Rails app. This is very valuable! Now you can use this app from anywhere. You can even share it with your friends. Just send them a link.

We started from nothing. Now we have a web application running on the Internet. This is awesome!

What’s next

Day 6: Task Views – Show a completed task

music_show
Photo by rodrigosa

Showing a completed task

Let’s add our status to show view. In order to do it, we need to add a new paragraph tag. If a task is completed, we want to display text: “Completed. Yay!”. We’re going to use our completed? method to determine whether we should show this section or not. This is what it’s going to look like. Go ahead and put this code in show view before Edit link.

Code to show a completed status

Don’t forget to start a server if you don’t have it running already. Go back to your browser and navigate to http://localhost:3000/tasks/1. Look, our task shows as completed, Yay!

n_rails_show_completed_in_a_browser

Adding a status to task listing

The last change that we’re going to make is adding a status to list view. We want to see which task is completed and which is not. This is really simple. Open up app/views/tasks/index.html.erb. We’ll need to add a new HTML table row. We will show the text “Completed!” if a task is completed.

ruby_on_rails_adding_status_to_task_listing

Go back to the browser. Go to: http://localhost:3000/tasks. You should see “Completed!” next to our first task. Just so we see the difference, let’s add a new task. Click “New Task”, enter “Learn how to program better”. Click “Create Task”. Click “Back” link to return to the task listing. You should see two tasks. One is completed. Another one is not.

completed_on_task_listing_screenWe learned how to program, now we need to learn how to program better.

What we just covered

We’ve made great progress! We wrote our first web application using Ruby on Rails. How cool is that? We went through basics of Rails framework. We understood how Models, Views and Controllers work together to deliver a web page to a user. This time we did everything ourselves. We generated a database migration. We used an attribute method on Task model. We looked at how TaskController renders views using actions. At the end of this chapter we added the ability to complete a task. Then we displayed this information on show, edit and list views.

Now we have a fully working todo application. Let’s put it on the Internet and tell the world about it.

Day 7: Deployment

Learn How To Program and become a Better Software Engineer with Alex Tamoykin