App Creation

In this book, we are going to create a real application that will track user's mood daily, and will show results in a calendar. It will also include a history of recent user mood so he could always review and update them if needed.

Ok, so let's create your first app. To do it, you will need motion command:

motion create superapp

Of course, superapp can be changed to whatever name you want to use.

This command will create a "superapp" folder in your current directory, that will contain your application's source code. Let's check what does it have:

app folder will contain 90% of your app's source code. app_delegate.rb is the first file of your app - you will decide there what to do when the app has been opened, closed, etc.

spec folder is for your tests. It already has one test, and we will learn how to write them later.

resources folder is for all your media and other files, such as images, icons, fonts, etc.

vendor directory can be used as a directory for all libraries that you will use in your project.

Gemfile is a file where you will add your Gem dependencies.

Rakefile is a settings file. You will add your Cocoapods dependencies there, will set app's name, version, etc.

I bet you want to try to launch your app. You can do it already, with rake command. But first, make sure you are in your project's directory. (you can Change Directories with "cd" command): cd superapp

iOS Simulator will be opened, and you will see your app. Rubymotion developers have added some code to add a Navigation Bar at the top, with your app's name so that it won't be just a black and boring screen. (it was in the first version of Rubymotion!)

You can also try to launch the app in other iOS simulators. To do it, add a "device_name" parameter to your "rake" command, and specify the device name. To view all your devices, open Xcode, and from its menu - Window -> Devices or just press CMD+Shift+2

In my case, if I would like to open app in iPad Air, I would need next command: rake device_name="iPad Air"

Do you still remember about git? We need to use it for version control. Let's tell it that we just initialized a project with git init command. You may notice .gitignore file - it is a set of rules that tells what files should be ignored and remain untracked in your repository. Default Rubymotion app template already has some files there, but you may want to update it according to your needs. For example, all Mac users always have a problem with unwanted .DS_Store files - just add them to it, and they will never be tracked.

Ok, so git repository has been initialized, but no files were added to it at this moment. To do it use git add command, and specify what exactly you want to add to the repository. If you want to add whole you project (you do!), use git add .

As you may know, dot in the previous command represents current directory. If you would like to add only /app directory, you would use git add ./app

At this moment, git started to track files. When you reach some milestone, you would need to commit (save) changes. Right now nothing has been committed, and you can make it sure with git status.

Git says it found some new files. Let's make our first commit since we just created a new project, initialized a repo, and ready for development. I would consider it as a milestone, and would save all changes with git commit -m "Superapp initialized!" You can use whatever message you want inside the brackets, but remember that this message will be used by your coworkers to understand what has been done in this current commit. For example, later we may use

When all changes have been committed, you could try to experiment with git status. Try to change "/app/app_delegate.rb" by adding some useless text to it, and saving the file. Check what git status will tell you.

We finally have our first iOS app launched! Let's move next to learn how to make it do something.

Book Index | Next