Friday, September 19, 2014

XCode 6 tips: storyboard zoom, ios 7 simulator, check id boolean type broken


1. In order to zoom xcode storyboard, right click on the storyboard window, and select the zoom percentage on the context menu. The shortcut key is too complex to remember.

2. As ios 7 and ios 7.1 are still used by many devices, so in addition to the ios 8 simulators installed with xcode 6, it is better to go to xcode preference->download menu to download the ios 7 and ios 7.1 simulator  for testing.

3. in ios 7,  the usual way to check whether an object is from boolean type is using
NSNumber * n = [NSNumber numberWithBool:YES]; 
if (strcmp([n objCType], @encode(BOOL)) == 0) {
    NSLog(@"this is a bool");
However the above way has broken in ios 8, the workaround is adding an additional check for the classname as below
 if (value != nil &&  [value isKindOfClass:[NSNumber class]] &&
        ( (strcmp([value objCType], @encode(BOOL)) == 0 ||

           (__bridge CFBooleanRef)value == kCFBooleanTrue || (__bridge CFBooleanRef)value == kCFBooleanFalse) ) ) {
    NSLog(@"this is a bool");

No comments:

Post a Comment