BetaDesigns( Blog ) Flex and Component Development

23Dec/110

Getting Static Libraries to link correctly in XCode workspaces

I just answered a question on StackOverflow about how to fix dependency issues in xcode workspaces when linking static libraries. This is just a post to remind myself.

StackOverflow Post

On A side note if the files within the library are only to be used in Storyboards then you need to explicitly reference them otherwise the compiler will remove them and you will get Run time errors.

The easiest way to do this is to create a Class with the same name as the library and each file you want to force for inclusion you should do the following.

  1.  
  2.  
  3. -(id) init
  4. {
  5. [CustomClass1 class];
  6. [CustomClass2 class];
  7. etc....
  8. }
  9.  

Then inside your main application

  1.  
  2. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  3. {
  4. //Force inclusion of files.
  5. [CustomLibrary class];
  6. return YES;
  7. }
  8.  
12Nov/110

XCode localization Reminder.

Just a quick reminder for myself for creating localization files in the terminal for xcode projects.

cd to project directory.

find . -name \*.m | xargs genstrings -o en.lproj

The above will find all .m files in all subdirectories and extract the NSLocalizedString().

10Jul/100

Useful Xcode breakpoints for debugging

Just a quick list of the most useful breakpoints I have found for debugging purposes. This is more of a personal reference so that I can add them back to any new install of Xcode.

objc_exception_throw
[NSException raise]
malloc_error_break

In addition here is a great tech paper on debugging in xcode called Mac OS X Debugging Magic

And here is a nice tutorial for using instruments to debug

3Jul/100

Custom XCode Logger

I came across this method for creating a Debug Logger for XCode projects.
Basically you create a macro that says only process this piece of code if we are running in debug mode. This allows you to create logging throughout your application without having to worry about removing it before you do a release build as it won't be included in the release code.

To begin you need to add a GCC_PREPROCESSOR_DEFINITIONS | DEBUG=1 to your projects TARGET>Get Info>BUILD settings.

Next go into YOUR_APPLICATION_NAME_Prefix.pch file ( located under Other Sources ) and place the following macro.

  1.  
  2. #ifdef DEBUG
  3. # define trace(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
  4. #else
  5. # define trace(...)
  6. #endif
  7.  

This will create a custom Logger that can be used in the same way as NSLog except that it will output a more descriptive message showing the location and line number of where the log item is located.
edit: I have cheekily renamed it to trace();

  1.  
  2. trace( @" Does my debug tracer appear in production code? %@",
  3. @"NO!" );
  4.  
3Feb/102

Custom Eclipse Style XCode shortcuts

After using eclipse for so long i have become a custom to my shortcuts and xcode just doesn't stand up to the job as far as i am concerned so here is a small list of the custom key bindings i have setup for myself. I will add more as I create them.

To create a custom key bindings file goto XCode>Preferences>Bindings> Duplicate an existing binding and name it whatever you want then go to and open the file you just created in a text editor so you can see the xml output.

~/Library/Application Support/Xcode/Key Bindings/*.pbxkeys

A good list of available commands can be found here

1. Duplicate code!

I can't believe xcode doesn't have this in Eclipse you simple select your text and press Ctrl + Alt and either Up or Down on the keypad and it will duplicate your code placing it either above or below the current selection. It will also reselect the newly duplicated code so that you can duplicate it as many times as you like.

<key>^~\U700</key>
<array>
<string>copy:</string>
<string>moveUp:</string>
<string>moveToEndOfLine:</string>
<string>insertLineBreak:</string>
<string>insertNewLine:</string>
<string>setMark:</string>
<string>paste:</string>
<string>selectToMark:</string>
</array>
<key>^~\U701</key>
<array>
<string>copy:</string>
<string>moveDown:</string>
<string>moveToBeginningOfLine:</string>
<string>insertLineBreak:</string>
<string>insertNewLine:</string>
<string>moveUp:</string>
<string>setMark:</string>
<string>paste:</string>
<string>selectToMark:</string>
</array>
2. Delete Line.
Deletes the current line your cursor is on. press Ctrl + D.
<key>^d</key>
<array>
<string>cut:</string>
<string>selectLine:</string>
<string>cut:</string>
</array>