Saturday, October 30, 2010

NSDictionary & NSMutableDictionary keys

NSDictionary keys must implement NSCopying. I required a map that used an UIView as a key, which does not implement NSCopying. The solution:


UISwitch* view = [[UISwitch alloc] init];


NSMutableDictionary* controls = [[NSMutableDictionary alloc] init];

[controls setObject:value forKey:[NSValue valueWithNonretainedObject:view]];


value = [controls objectForKey:[NSValue valueWithNonretainedObject: view]];

Thursday, October 28, 2010

Renaming XIB problem

Renaming an XIB using XCode's 'Rename' caused a crash. After app launched it failed trying to load the XIB because it was trying to load it with the previous name. The fix was to open the main window XIB with an XML editor (Dashcode) and manually change the view controller name [key=IBUINibName].

Sunday, October 24, 2010

OCUnit/SenTestingKit Notes

1. NSLog can be used from test cases, view output with .../Applications/Utilities/Console File->Open Console Log

2. Loading resources during unit testing doesn't work from mainBundle e.g. use:

NSString* path=[[NSBundle bundleForClass:[self class]] pathForResource:@"fname" ofType:@"plist"];

VS

NSString* path = [[NSBundle mainBundle] pathForResource:@"fname" ofType:@"plist"];


3. CGRectZero causes tests failure, CGRectMake(0, 0, 0, 0) does not.

Tuesday, October 12, 2010

Remove NSLog from release builds

Add the following to project's .pch

#ifndef __OPTIMIZE__
    #define NSLog(...) NSLog(__VA_ARGS__)
#else
    #define NSLog(...) {}
#endif


More info