Using Subversion with Xcode

With several people working in teams on the final project I thought I’d post how to setup and user Subversion (SVN) with Xcode. Like other IDEs, Xcode allows you to perform version control from within the IDE.

The following was derived based on notes provided by Amy Ciavolino — thanks Amy!

Setting up a Repository

If you want to use SVN, you’ll need to have access to a SVN repository online somewhere. You could host your own SVN repository, or if you’re creating an open source project you could leverage Google Code which will provide free public SVN access. Setting up a new SVN repository with Google Code is pretty painless. Create a Projectto get started.

Adding a SVN Repository to Xcode

  1. To add an Xcode repository to Xcode select SCM (from the menubar) → Configure SCM Repositories…
  2. Under the Repositories tab, click + to add a new repository…
  3. Under Name enter the name you want to give the repository and be sure that Subversion is selected under SCM System

    Naming the Repository

    Naming the Repository

  4. Enter all of your SVN credentials into the dialog (substituting your own values)…

    Entering the Repository Info

    Entering the Repository Info

  5. If all goes well, you’ll see the repository added to your list of SCM repositories…

    The Added Repository

    The Added Repository

Importing a Project

  1. Before you can import, you’ll have to have added the SCM repository to Xcode
  2. From the repositories screen, select the Import button from the toolbar
  3. Browse to the folder that contains the Xcode project and select Import
  4. If all goes well you’ll get a message indicating that the import was successful…

    Successful Project Import

    Successful Project Import

Checking out a Project

  1. Before you can check out, you’ll have to have added the SCM repository to Xcode
  2. From the repositories screen, select the Checkout button from the toolbar
  3. Browse to the directory you want to store the project, select a name for the folder, then then select Checkout
  4. If the checkout goes well, you get a message asking if you want to open the checked out project in Xcode…

    Open Xcode Project

    Open Xcode Project

  5. You’ll need to do is to tell Xcode that you want to perform SCM operations against the repository you checked out from. To do so, select SCM (from the menubar) → Configure SCM For This Project
  6. From the General tab click the Configure Roots & SCM… button (top right)
  7. Select the repository from the drop-down that you’d like to perform operations against, then press OK like so…

    Selecting the Project Repository

    Selecting the Project Repository

  8. After having performed a checkout, various SCM functions are now available off of the SCM menu item (e.g. commit, update, diff, etc.)

Additional Information

Capturing Screenshots

There are several different ways to capture iOS screenshots. Since you’ll need to do this for various upcoming final project deliverables, I thought I’d outline several techniques here.

Simulator with Window Decoration

If you want a screenshot with the simulator frame showing, then the easiest way is to utilize OS X’s built in screen capture utility. Simply press Command-Shift-4 (release) then hit the space bar. This will display a little camera icon where the cursor was and will highlight the currently selected window to capture. Once you’ve selected your window, simply click the mouse/trackpad to have OS X save it to your Desktop as a PNG (or press ESC to cancel).

Capture with Decorations

Capture with Decorations

Simulator without Window Decoration

If you’re on the iPhone Simulator, the easiest way to take a screenshot of just the screen is to hold down Control and select “Copy Screen” from the “Edit” menu. This can also be accessed by pressing Command-Control-C.

Copy Simulator Screen

Copy Simulator Screen

Then, the easiest way to create an image from the clipboard is to open the Preview app (can launch via spotlight) and select “New from Clipboard”.

Paste Simulator Screen

Paste Simulator Screen

Then you can simply save the image as a PNG.

Directly from iOS Device

There are 2 easy ways to get screen captures from an iOS device — through Xcode or using iOS’s built in screen capture utility. I prefer using Xcode as it takes a lossless PNG images, whereas the device seems to capture lossy JPG images.

To capture using Xcode, plug in your device and bring up the Organizer by selecting “Organizer” from the “Window” menu.

Xcode Organizer

Xcode Organizer

Once open, select your iOS device and then select the “Screenhots” tab. To capture a screenshot, simply press the “Capture” button and the most recent screenshot taken will be displayed in the right panel and all screenshots will appear in the left panel. Though not obvious, you can easily save any image on the left by simply dragging it out of Xcode’s Organizer into a Finder window.

Xcode Capture Screen

Xcode Capture Screen

To capture using the iOS’s built in screen capture utility simply hold the home button and press the sleep/wake button. You should see an on-screen flash when a capture is taken. The screenshot will then appear in an album in your Photos app, which you can then email or sync off of the device.

Lecture 15 — Advanced Xcode Tricks

Advanced Xcode Tricks

Advanced Xcode Tricks

Source code form this lecture:

Lecture 13 — Xcode Tricks

Xcode Tricks

Xcode Tricks

iPhone Simulator Shell Shortcuts

I thought I’d share the following two iPhone Simulator shortcuts that I wrote and use in my bash shell (the default Mac shell). I’ve found these shortcuts useful if you need to browse the contents of an application that’s installed under the simulator. For example, if you’re persisting data and need to verify that it has been written out successfully.

The following function allows you to type cdlatestappdir into the Terminal and will switch the directory to that of the last app installed under the latest installed SDK. You can optionally specify an argument (e.g. cdlatestappdir 4.0.2) to instead cd into the last app installed under a given SDK.

function cdlatestappdir {
    cd ~/Library/Application\ Support/iPhone\ Simulator/
    cd ${1:-$(\ls -d -1 [0-9]* | \sort | \tail -1)}/Applications/
    cd $(\ls -1 -t | \head -n 1)
}

The following function has the same usage as the cdlatestappdir function, but instead opens that directory in a new Finder window.

function finderlatestappdir {
    pushd . > /dev/null
    cd ~/Library/Application\ Support/iPhone\ Simulator/
    cd ${1:-$(\ls -d -1 [0-9]* | \sort | \tail -1)}/Applications/
    open $(\ls -1 -t | \head -n 1)
    popd > /dev/null
}

To use these functions simply add the two functions to your ~/.bashrc file.

Xcode Cheatsheet

Given that many of your are just starting to learn Xcode, I thought I’d take a moment to share Mike Clark’s great free Xcode shortcuts cheatsheet. This cheatsheet covers many “essentials” that I use regularly and may be worthwhile to bookmark or print out while you’re getting up to speed with Xcode.

Xcode Shortcuts

Xcode Shortcuts

Mike also sells a couple of Xcode screencasts through The Pragmatic Bookshelf if interested.

Follow

Get every new post delivered to your Inbox.