Say you've got an iOS app talking to a backend api. Maybe this api runs as localhost on your machine when you're in development and maybe you also have staging and production environments out in the cloud somewhere. What's the best way to set this up?

I've gone with an encapsulated pList... setup as follows.

This is my pList file.
I encapsulate that in a class called EnvironmentVars.

After which, I can access it as follows from anywhere. This is an example of using it to create a NSUrl object.
Objective C code can be terse. I find it's best to exercise encapsulation to the extremist point to maintain sanity.

I'm setting up a new Mac Mini for Ruby on Rails development. It was pretty much headache free. I knew I needed my app to use MySQL so I wanted to set things up to incorporate this. Here's the list of components that need to be installed in the order shown.
  1. Xcode (with Command Line Tools)
  2. Homebrew
  3. MySQL & MySQL Workbench
  4. RVM (installing lastest Ruby 1.9.3)
  5. Install gems to against 1.9.3 gemset: rails, bundler, mysql2, activerecord-mysql2-adapter
  6. Rubymine (My editor/IDE of choice for RoR development)
Once all of these are installed, you can use Rubymine to create a new rails project, configure your database.yml file, generate a model (with a migration), and run rake db:migrate to confirm that all connections are up and running. We'll step through this at the end.

Install Xcode


Best done through the Mac App Store. Launch the App Store and search for xcode. Follow directions to install it.

Once Xcode is installed you need to install the Command Line Tools. This gets you lots of command line goodies we'll need for ruby and rails development. (One main one being the gcc compiler, integral for running Ruby.)

Within Xcode, go to Preferences > Downloads > Componenents. From here, you can install the 'Command Line Tools'.

Install Homebrew


Homebrew is a package manager for Mac OSX. It's currently quite popular and I like it as it seems to work the most smoothly with the latest components new in Lion. Here's a comparison between the different options in this area.

Lion ships with Ruby installed, so we can use this default version to install Homebrew. Run this in your terminal: 

$ ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

Install MySQL


Super easy now that we have Homebrew.

$ brew install mysql

When this finishes it gives you some instructions of a few things to do to set up the root account and different configuration options for startup, etc... read these and do what you think you need to do. I'm going to configure it to start when the system starts

$ mysql_install_db --verbose --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/mysql/5.5.15/com.mysql.mysqld.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist

You may still need to manually start it at this point before you can log in.

$ cd /usr/local/opt/mysql ; /usr/local/opt/mysql/bin/mysqld_safe &

Now, login.

$ mysql -uroot

If this is successful, you're almost there, the only thing left is to install the MySQL WorkBench!

Create a connection using the default configurations: user: root, host: 127.0.0.1, port: 3306. Now you can create databases against this connection through this interface. We'll do this later though!

Install RVM


I used this as a step-by-step installation guideline.

But, basically... for installation. You just need to run this from your terminal:

$ curl -L get.rvm.io | bash -s stable

Now we can install the latest Ruby (or which any you need) First, list all the ruby versions available for installation:

$ rvm list known

I'm going to install the latest version, 1.9.3.

$ rvm install 1.9.3

Before we start installing gems, lets tell RVM the version of ruby we want to install gems against.

rvm use 1.9.3

Installing Gems for Rails Development using MySQL


$ gem install rails
$ gem install bundler 
$ gem install mysql2
$ gem install activerecord-mysql2-adapter

Install RubyMine create a new Rails project


Once RubyMine is installed, launch it and create a new project. 
  • Make sure to specify the project type as 'Rails Application'.
  • Select the ruby version you want to use. 
  • If RubyMine doesn't know the Rails version it should use, you will need to click the '...' box next to the Rails Version dropdown. RubyMine will go and get it!
  • Click 'ok' and we're ready to go!

Configure your database.yml File


It should look something like this:

Test that everything is up and running.


$ rails g model user
      invoke  active_record
      create    db/migrate/20121029132052_create_users.rb
      create    app/models/user.rb
      invoke    test_unit
      create      test/unit/user_test.rb
      create      test/fixtures/users.yml

Edit your migration file to reflect the columns you'll need in your table. If all this doesn't make sense, spend some time researching ActiveRecord and Rails database migrations.

If you need a cheat sheet to help with defining your columns, check this out.

Now you should be able to run this:

$ rake db:migrate


BOOM. Easy Peasy.


I'm currently getting new mac mini ready for Ruby on Rails, iOS and Android development. I had Xcode 4.3 installed by default but I didn't have the standard /Developer directory where you get all the lovely command line tools used for Ruby development. Some of my gem installs were working, but some were not. Was seeing stuff like this from the terminal:

$ make
-bash: make: command not found

Weird, right? Where are my command line tools?

Turns out, in Xcode 4.3 and later, you have to specifically install these and they aren't in the /Developer  directory.

Once Xcode is installed. Go into Preferences > Downloads Tab > Components Pane

From there install Command Line Tools.

Boom. Terminal works.

Android requires that you do all network processing on non-UI threads. This is good business as it means unexpected exceptions aren't going to crash your app. It can be a little problematic when you need to be notified of the different outcomes of your various network activity. You need to notify an activity, it needs to notify one of it's components.

The Callback Approach

This is essentially like handing a reference to the caller of the process. The process then calls an appropriate method on the caller, depending on the outcome.


The Guava EventBus Approach

This approach decouples the caller from the process. The caller can register for different events on the event bus after which, any process can put that event on the event bus. The registered processes with get notified.

You have to define those events but they can be empty or you can wrap anything you need in them.
Then all you have to do is subscribe for the event from the activity. It doesn't matter what you call the method... what matters is the parameter must match an event that will be put on the message bus.

Why is the event bus better? 

Well it decouples the method responding to the outcome of the network activity or whatever from the task doing this. You don't have to pass a reference of the thing doing the responding to the task. Another benefit here is that anything can register to respond to this event. Be it the activity, or one of it's fragments, it's action bar, or whatever. Nice!

This is the 2nd in a series of posts concerning iOS development. I want to begin my app by choosing a data storage technique. I'm leaning towards Core Data because I want to hook it up with my models using xCode's for iOS 5 storyboards... but I realize I need to do my due diligence and research all the options. So, here they are with an outline of my needs.

The vision for my app will definitely involve some robust storage capability. Without saying too much, the foundation for my app will be a users ability to build, track, and share recipes. I'd like to investigate my options for this. My research has concluded that in iOS development you have a number of on-device data storage techniques as your disposal.

Property Lists - These are sort of key-value pair storage techniques. You define them programmatically and they're loaded when the app starts. I suppose this is the simplest, most basic option. It's limitation would be you don't get any relational capabilities.

SQLite - With this option you get the relational thing at least in your database because it's SQL. It's my understanding that the support for this comes from some C libraries included into the iOS framework. Since SQLite works off a single file, you can seed this with your data and load it into your application. I plan to investigate this further in another post. It appears this option involves the requirement of writing your own sql queries. Boo.

Core Data - This is sort of the Maserati option. Core Data is provided and customized to work with xcode development. You get your relational structure. You hook it to your data models via xcode. You don't have to deal with database connections or schemas. It's basically the only option where you get an ORM feeling.

My decision is to move forward with Core Data. Not only will it satisfy the curiosity of how storyboards work with it, but it's the ORM option. And I love ORMs. Don't get me wrong, I can write my fair share of SQL, but if there's something out there that does all this for you... why not use it?