Archive for June, 2011

Setting up xCode 4 Projects

Friday, June 24th, 2011

Every time I start a new xCode project i do it a little differently. I include files in some and settings in others. I have decided to put them all here to make sure i don’t miss any. If you have any other project settings, scripts, snippets or useful utils please drop a comment.

1. Enabling and dealing with Zombies:

This allows you to find errors that come from delloced objects being called upon. That normally just gives you the useless error bad access. with this enabled it should take to a class or function when you see the bad access error. This can be dealt with in 2 ways either enabling zombies in the editor thus allowing you to debug it in xCode or using instruments. If the first method does not work for you try the second.

Method 1 xCode Debug:

  1. get to the run settings by press: cmd+alt+r
  2. from the left nave select “RUN  yourApp.app”
  3. select “Arguments” from the right tab system
  4. expand if not already expanded the environment variables
  5. add NSZombieEnabled the name parameter and YES to the value parameter

Method 2 instruments Debug:

Rather than take you through it Mark Johnson has created a good video that talks you through it.

Check out his blog post for more details: http://www.markj.net/iphone-memory-debug-nszombie/

2. Replacing NSLog with PSLog

PSLog is a NSLog replacment. I have seen it arround for a while now. Basicly it gives you a bit more info like where log is called from. The only problem with it, is the dependancy it creates on having to keep importing PSLog in every one of your projects.

I modified it so you can use NSLog in your code and at compile time in debug mode it replaces your NSLogs with PSLogs. During deploy it replaces NSLog with comments. This way it removes any depandacies on the PSLog function.

How ever this only applies to the PSLog function it self none of its expanded counter parts like PSLogDebug. Using PSLogDebug will maintain a dependancy.

Check it out:

https://github.com/abeazam/PSLog.git

If you #import “PSLog.h” in the .pch file in the support group in your project you wont have import it in every file you want to use it. which Helps the whole dependancy issue.

TODO, FIXME converted to warnings

I duno if you noticed but if you add a //TODO: or //FIXME: comments it appears  in the function menu. The problem with that though is you need to be in the class to see the list. Ideally what I wanted was a list of todos that I can see them all in one place. You can do that by adding a bash script that adds them as warnings.

  1. Select your project in the left hand menu
  2. Select your project in the target right hand menu
  3. Click “Add Build Phase” in the bottom right.
  4. Select “Add Run Script”
  5. Past in the script below and your done 🙂

i think this guy might have come up with it: http://deallocatedobjects.com/2011/05/11/show-todos-and-fixmes-as-warnings-in-xcode-4/

Snippets
Snippets are one of the things that stood out to me in xCode. Here are a few of mine:

Completion shortcut – log
Completion scope – function and method

Completion shortcut – imp
Completion scope – processor directive

If you want to make a variable just stick them in <#here#>.

Crash Log Server

http://quincykit.net/
https://github.com/therealkerni/QuincyKit

Sends the crash report to a server with a single line of code. I have not tried the push notifacsion but every thing else seems to work resonably.

http://quincykit.net/

Please let me know if you find anything else that helps keep a project in shape.