Saturday, January 31, 2009

XCODE 3.1 Other C Flags

I am following the instructions from this post in order to get rid of NSLog() in release mode builds. Unfortunately on my installation I do not see the Other C Flags entry in the Target Build Info. I went ahead and created an User Defined entry with the name OTHER_CFLAGS and value -DDEBUG. By visually inspecting the build output I see the -DDEBUG flag in the compiler command line.

Friday, January 30, 2009

iphonelite3

I created a github project around an iphone project. You can read all about it here

http://iphonelite3.org

Eclipse matching end of line

I need to append a " character just before the end of line in eclipse. For some reason $ does not work for matching the end of line. You can match on \n but then in the replace field I could not find a way to put \n back, it shows in the text as '\n' instead of new line.

My fix has been to define a group in the mach field and then use the group on the replace field. A bit annoying but easy to use once you know about it.

(\n) -> "$1




For matching the start of line ^ does not work either, for me. So a similar approach is

^(.) -> "$1

CORRECTION: to get \n to work you simply need to check "Allow escape sequences".

Enjoy :-)

Wednesday, January 21, 2009

Fixing bad new lines

Use the following command to translate ^M characters in a file to usual end of line characters.

cat FILE_TO_TRANSLATE | tr ^M \\n > FILE_TO_TRANSLATE_NEW

NOTE: to get the ^M type Control-V Control-M, the ^M is just one character not two.

Sunday, January 11, 2009

object_setInstanceVariable with a double value

In Objective-c you cannot use object_setInstanceVariable to set a double value inside an instance, it can only be used to set an object. You have to use code similar to the following instead an Ivar like in the sample code below.


if ((var = class_getInstanceVariable(class_pointer, name)))
{
varIndex = (void **)((char *)obj + ivar_getOffset(var));
*varIndex = value;
}

Saturday, January 10, 2009

Release synthesized properties?

As of the time of this post when searching for the above sentence you get more chemistry replies than objective-c ones. So I decided to provide an anchor point for objective-c (and implicitly iPhone) discussion on this topic.

So the question is: when you hold an instance of a class in a property do you have to release the instance in your dealloc method? In the example below the ServerDownload class contains an instance of UserAccount. For now I answer YES to this question and use a release in my dealloc.

@class UserAccount;

@interface ServerDownload : NSObject {
UserAccount * userAccount;
}
@property (nonatomic,retain) UserAccount * userAccount;
@end


@synthesize userAccount;

- (id)init {
}

- (void)dealloc {
[userAccount release];
}



Another alternative would be to set the property to nil. I do not use set-to-nil because there are valid concerns that a custom implementation of the setter may have side effects.

self.userAccount=nil;


Let me know what you think...

Thursday, January 8, 2009

Eclipse 3.4 and svn 1.5

So you upgraded your command line svn to 1.5. Things will start to happen behind your back but there is no need to panick.


  • any local project that you touch with the command line tool will be upgraded to 1.5
  • eclipse/subclipse won't be able to touch the project anymore
  • upgrading subclipse and dependencies should fix that
  • now you may get errors like"Retrieval of mergeinfo unsupported"
  • make sure that under Prefences/SVN/SVN Connector the checkbox "Show merged revisions" is not checked


The good news is that as soon as your svn server will be upgraded to 1.5 you will be able to do much easier merges, see http://subversion.tigris.org/merge-tracking/func-spec.html