Whether you’re running for the hills after Adobe’s announcement, or just looking to broaden your skillset, Objective-C is a worthwhile investment to add to your portfolio. I love apps. My mom loves apps. Who doesn’t love apps? While I may not agree with a lot of he-who-shall-not-be-named‘s policies, Apple has something amazing going for it: All its products are remarkably synergetic. It’s something I’ve noticed way back when I got my first macbook and iPod, and it’s only gotten stronger since then. If you learn to master Objective-C, you will obtain a skillset that is as versatile as Apple’s product line (and once the iRefridgerator comes out, you’ll be ready to slap Angry Birds on it, as well).

This series of lessons aims at the Flex developer who wants to develop for iOS, however most of the material should be perfectly understandable to anyone who has experience with Actionscript, Javascript, Java, etc. I plan to (hopefully) make this a daily lesson, so each article will be narrowly focused on one topic and (hopefully) not too intimidating. That being said, let’s begin!

Before We Begin

What you will need for these lessons:

  • Snow Leopard or Newer OS
  • Xcode 4.2 (Warning: This app is a beast. Make sure you’re not using your three year old macbook to develop with it.)
  • Recommended: An iPhone and/or iPad and developer’s license.

Your New Friends

Xcode 4.x
The main application for desktop and iOS development. Like Flash Builder, Xcode is a swiss army knife of tools, from coding, to component layout, to versioning and unit testing.

iOS Simulator
A virtual simulation of the iOS device you are developing for. Very handy for quick building and testing without the need of plugging in your device.

Instruments
Like the system profiler bundled with Flash Builder Professional, this monitors in real-time the state of your application’s memory allocation, processes, and more.

Setting up a Project

In this lesson we won’t actually write any code, just create a project and observe how the tools lay everything out for us. Let’s begin by opening up Xcode.

  1. The first thing you should notice is the Xcode welcome screen. Just click the Create a new Xcode project button to launch the wizard.
  2. At this point, you’ll see there are quite a few options for you to choose from, conveniently grouped by iOS and Mac OS X. under iOS, make sure Application is selected, then choose Master-Detail Application on the right side. Click Next.
  3. Now the wizard wants you to define the project. Set the Product Name to “Tutorial1,” the Company Identifier to whatever base package structure you want (in my case, I used my standard, “com.schelterstudios”). Set the Device Family to iPhone, and make sure only Use Automatic Reference Counting is checked. We’ll go over the rest of what these fields mean in a later lesson.
  4. Choose a folder to save your project in. (Xcode will create a folder with the name of the project for you, so just choose the parent folder for this step.)

At this point, your window should look like this:

Now, I’d first like to direct your attention to the View buttons in the top right corner of the editor. These show and hide the main view sections of Xcode. From left to right, you have Navigator, Debug and Utilities.

  • Navigator - This view is for traversing throughout all the folders and files in your workspace. There are various tabs within the view to provide different ways you can drill down to the code you need to access.
  • Debug - Basically does just what it sounds, this view shows you your traces and live variables.
  • Utilities - Utilities handles everything else you need, such as configuration, documentation, and formatting while in code view, and component insertion and editing from the interface builder view.

The top center of the editor displays the running state of the application. This gives feedback on the linkage between Xcode and the Simulator or your device, and will also identify any build issues it may find. To the left of that is the Scheme. These drop-downs identify the scheme you are using when running your application. You can configure various schemes for different build routines, but that stuff gets pretty advance pretty fast. The right-side drop-down alone is sufficient for most projects, which is what you’d use to switch between testing via iPhone simulation, testing via iPad simulation, and testing on your device.

Finally, the top left has the Run and Stop buttons, which is what you’ll use to start and stop your build tests. If you hold down the Run button, you can also switch to Test, Profile and Analyze.

  • Run - Runs the application in the simulator or on your device. This is the standard way to view your app.
  • Test - Executes your unit tests.
  • Profile - Runs the application and shortcuts you to the Instruments app.
  • Analyze - A quick run-down by the editor to provide suggestions of possible leakages or other inefficiencies.

This is the extent of the lesson for now. At this point you can check out the application built so far by the Xcode wizard by making sure the Scheme is set to iPhone 5.0 Simulator and pressing the Run button. The iOS Simulator should pop up and display the screen below.

As you play around with it, you can see that the simulation lets you rotate, swipe, shake, hide the app, etc. It also comes with a few other apps that you can code your application to interact with, such as photos or contacts. Not too scary, right? In the next lesson, we’ll be covering the specifics of the files generated by the wizard, and Objective-C class structures. Also, feel free to leave feedback to let me know how you feel about the pacing of these lessons. My aim is to make migration as comfortable as possible, while also focusing on the specifics of each aspect of Xcode and Objective-C without ending up with a massive wall of text in a single post.

Tagged with:
 

9 Responses to Flex to Objective-C: 1-Intro

  1. Very useful, keep it up. I like the bite sized chunks. I’ve had XCode installed for ages and never really used it for anything useful.

    It would be nice if there was a way to subscribe to new posts via email.

    • Steve says:

      Thanks for the comments! Stefan, haven’t messed around with wordpress subscriptions, but there’s a button in the top corner to add the RSS feed, which you can use with any RSS widget/app.

  2. Adrian says:

    Hi, looks great!
    Looking forward for the next parts ;)

  3. James says:

    This is great! I set-up a mac book the other day with Snow Leopard and XCode. Coming from a Flex background there were some sketchy attempts at Flex to Objective-C migration tutorials but hopefully this one is going to hit the nail on the head ;) I’m looking forward to the rest!

    As a suggestion, an article on syntax ‘translation’ would be really useful!

  4. Zed-K says:

    The idea of an Objective-C tutorial serie for Flex developers seems very promising to me, bookmarked ;)
    Can’t wait to read the next articles =)

  5. Great! Just in time too for a lot people I suspect.

  6. Joe says:

    Sweet… was learning JS (extreemly similar to AS).

    Why not have screencasts as you explain? faster for you and for us :)

  7. Matt Perkins says:

    USEFULL!!!

    I’m moving to developing for iOS from AS3 and I’m diggin the explainations on your site!

    Keep it up!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Set your Twitter account name in your settings to use the TwitterBar Section.