Search
Rich's Mad Rants
Powered by Squarespace
Thursday
Feb272014

Moving up to the Big League

I just wanted to let everyone know that I've accepted a position with the DevPubs team at Apple. I didn't think I'd be going back to a regular office job at this point, but this opportunity is far too interesting to pass up.

Unfortunately, that means my tech writing energy will be entirely focused on my day job--so you probably won't see any new blog posts, magazine articles or books from me. Of course, it also means I won't feel so guilty about not posting as often as I would like.

Even though I won't be posting new content, I will try to keep this blog alive as long as the blog posts and bonus chapters remain relevant and useful.

I also won't be teaching iOS classes anymore. I'd like to thank all the students that I've taught over the last few years. The time that I've spent with you has been incredibly fun.

Now, go out and make something amazing.

Thursday
Feb062014

Article out at Peachpit.com

I have a new article out at www.peachpit.com. It's high-level advice for new developers. I talk about why you should use Arc, storyboards, auto layout, instruments and unit tests (as well as some of the disadvantages and problems with these technologies.)

 

-Rich-

Saturday
Dec282013

Setting Up Xcode 5 Workspaces with Multiple Repositories

Introduction

The WWDC 2013 session, Understanding Source Control in Xcode showed a really cool new feature. We could set up a workspace that contained a number of projects. Most of the time this would be an application and a number of static libraries. Each of these projects could have their own repository. Some might be hosted on a local OS X server. Others might be out on GitHub or other remote servers. It doesn't matter.

Xcode is supposed to be smart enough that when you check out the containing workspace, it recognizes these dependencies and can automatically download all the projects.

Unfortunately, there are two problems with this:

  1. Workspaces in the current version of Xcode 5 are badly broken. Specifically, if you create a workspace, and then create a project inside that workspace, Xcode will not create a git repository for that project, even if you ask for one.
  2. The Workspace itself must be under source control--however, there's no option to create a git repository when creating a workspace (only when creating projects). So, we must manually create the git repository.

The good news is, after a lot of trial and error, I've managed to find a way to set everything up by hand. Everything has to be set up just right, or it won't work. And, there are a number of steps that are easy to miss. However, once everything's in place, you can check out all the projects by simply checking out the workspace, as advertised.

Setting Up Our Projects

The first step is to set up all the individual projects. Each of these should be created as free-standing projects. Do not add them to any workspace yet. We'll take care of that later.

Additionally, each of the projects must be the working copy cloned from a remote repository. If you're using a project on GitHub, it's easy. You just clone a local copy of the repository. However, if you're creating a new project, things get a bit more complex.

Fortunately, if you have a Mac running OS X Server and the Xcode service on your local network, we can create projects directly on a remote repository with a local working copy. For complete details, please check out the Other Tools of the Trade bonus chapter from my book Creating iOS Apps: Develop and Design, Second Edition.

Setting Up Our Workspace

Once the project is setup and ready to go, we can create our workspace.

Now, we need to make sure that all the projects and the workspace are in separate directories. This isn't the way I typically organize my projects. Instead, I like to have a folder that contains both my workspace and all my project folders. Unfortunately that won't work. We need to place the workspace in its own folder. I recommend the following directory structure:

Once this is done, open the workspace and add our projects to the workspace. Then we need to quit Xcode. Simply closing the workspace won't be sufficient. We're going to manually create a repository for our workspace, and Xcode won't detect the new repository unless we actually quit and restart the entire application.

With Xcode shut down, open Terminal and navigate to our workspace's directory. Now, let's create a local get repository. Type the following commands:

bash$ git init
Initialized empty Git repository in /Users/rikiwarren/Develop/Sample Multiple Repository Project/Sample Workspace/.git/**
bash$ cat > .gitignore
.DS_Store
xcuserdata
^D
bash$ git add .
bash$ git commit -m "Initial Commit"
[master (root-commit) 49b2e6d] Initial Commit
 2 files changed, 12 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 Sample Workspace.xcworkspace/contents.xcworkspacedata

Note: Make sure you are only committing two files, .gitignore and your .xcworkspace file

Now, we need to create a remote repository for our workspace. Open Xcode again. Now, when you click on the Source Control menu, you should see the workspace repository, along with your project repositories. Select Source Control > Your Workspace > Configure Your Workspace.

In the Configuration Sheet select the Remotes tab, then click the + button and select Create New Remote. This will let you setup a remote repository, and it will make your local copy a working copy of that remote.

Configure The Project Repositories

Now, we need to configure the project repositories. Unfortunately, we need to quit and relaunch Xcode again before the options will be available.

For each project, select Source Control > Your Project > Configure Your Project. Then in the Configuration Sheet make sure the project is included as required during checkout.

Once this is done, commit and push these changes.

Note: We must commit and push the changes to our workspace's .xccheckout file. In my tests, Xcode did not always add this file to our repository. If it isn't being committed automatically, you may need to go back to the Terminal and add and commit it by hand.

That's it. We can now use Xcode's Check out an existing project command to clone the workspace and all our projects onto any other machine.

Hopefully much of this will be automated, and the bugs will be fixed in the next release.

Bug Reports

I have filed the following bug reports. Please feel free to file duplicates.

  • When creating a new project inside a Workspace, Xcode does not create Git repositories: Radar #15730261
  • There is no way to place a workspace under source control when creating it: Radar #15730266
Monday
Dec232013

Ho Ho Ho! (Merry Christmas, a bit early)

The last bonus chapter is finally complete. Other Tools of the Trade looks at source control, unit tests (including the new XCTest framework and setting up Bots), profiling with Instruments, and debugging.

All the information has been updated for iOS 7 and Xcode 5. It's 35 pages, and it's free! You can download it here.

Monday
Dec092013

Two new bonus chapters, available NOW!

I have just posted two additional bonus chapters.

"State Persistence and Restoration" covers recording the current state of the application's user interface, so we can restart the application exactly where the user left off. This chapter includes source code and instructions for the book's Health Beat project. It was originally written for end of chapter 6, but the sample code should be useable any time after that chapter.

"An Overview of iOS Notification Techniques" covers all the different methods for passing notifications around an iOS application, from direct messages and delegates to sending messages down object hierarchies and using the NSNotificationCenter. Here, I briefly describe each technique and list its major advantages and disadvantages.

Both PDFs are available for free. Please check them out.

-Rich-