'Convert to Modern Objective-C Syntax'...
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Tue, 26 Feb 2013 17:05:38 +0000 (18:05 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Tue, 26 Feb 2013 17:05:38 +0000 (18:05 +0100)
15 files changed:
ApplicationController.m
Config.m
ConfigsController.m
Enjoy.xcodeproj/project.pbxproj
JSActionAnalog.m
JSActionHat.m
Joystick.m
JoystickController.m
Target.m
TargetConfig.m
TargetController.m
TargetKeyboard.m
TargetMouseBtn.m
TargetMouseMove.m
TargetMouseScroll.m

index c87a6ee..4a4deea 100644 (file)
@@ -42,9 +42,9 @@ pascal OSStatus appSwitch(EventHandlerCallRef handlerChain, EventRef event, void
        ApplicationController* self = (ApplicationController*)userData;
        NSDictionary* currentApp = [[NSWorkspace sharedWorkspace] activeApplication];
        ProcessSerialNumber psn;
-       psn.lowLongOfPSN = [[currentApp objectForKey:@"NSApplicationProcessSerialNumberLow"] longValue];
-       psn.highLongOfPSN = [[currentApp objectForKey:@"NSApplicationProcessSerialNumberHigh"] longValue];
-       [self->configsController applicationSwitchedTo: [currentApp objectForKey:@"NSApplicationName"] withPsn: psn];
+       psn.lowLongOfPSN = [currentApp[@"NSApplicationProcessSerialNumberLow"] longValue];
+       psn.highLongOfPSN = [currentApp[@"NSApplicationProcessSerialNumberHigh"] longValue];
+       [self->configsController applicationSwitchedTo: currentApp[@"NSApplicationName"] withPsn: psn];
        return noErr;
 }
 
@@ -76,10 +76,10 @@ pascal OSStatus appSwitch(EventHandlerCallRef handlerChain, EventRef event, void
        Config* current = [configsController currentConfig];
        NSArray* configs = [configsController configs];
        for(int i=0; i<[configs count]; i++)
-               [[dockMenuBase itemAtIndex: (2+i)] setState: (([configs objectAtIndex:i] == current) ? YES : NO)];
+               [[dockMenuBase itemAtIndex: (2+i)] setState: ((configs[i] == current) ? YES : NO)];
 }
 
 -(void) chooseConfig: (id) sender {
-       [configsController activateConfig: [[configsController configs] objectAtIndex: ([dockMenuBase indexOfItem: sender]-2)] forApplication: NULL];
+       [configsController activateConfig: [configsController configs][([dockMenuBase indexOfItem: sender]-2)] forApplication: NULL];
 }
 @end
index de3c1cc..27ca4f0 100644 (file)
--- a/Config.m
+++ b/Config.m
@@ -20,7 +20,7 @@
        [entries setValue:target forKey: [jsa stringify]];
 }
 -(Target*) getTargetForAction: (id) jsa {
-       return [entries objectForKey: [jsa stringify]];
+       return entries[[jsa stringify]];
 }
 
 @end
index f6770cc..3168f8d 100644 (file)
 -(IBAction) removePressed: (id)sender {
        // save changes first
        [tableView reloadData];
-       Config* current_config = [configs objectAtIndex: [tableView selectedRow]];
+       Config* current_config = configs[[tableView selectedRow]];
        if([current_config protect])
                return;
        [configs removeObjectAtIndex: [tableView selectedRow]];
        
        // remove all "switch to configuration" actions
        for(int i=0; i<[configs count]; i++) {
-               NSMutableDictionary* entries = [(Config*)[configs objectAtIndex:i] entries];
+               NSMutableDictionary* entries = [(Config*)configs[i] entries];
                for(id key in entries) {
-                       Target* target = (Target*) [entries objectForKey: key];
+                       Target* target = (Target*) entries[key];
                        if([target isKindOfClass: [TargetConfig class]] && [(TargetConfig*)target config] == current_config)
                                [entries removeObjectForKey: key];
                }
 
 -(void)tableViewSelectionDidChange:(NSNotification*) notify {
     if (tableView.selectedRow < configs.count)
-        [self activateConfig: (Config*)[configs objectAtIndex:[tableView selectedRow]] forApplication: NULL];
+        [self activateConfig: (Config*)configs[[tableView selectedRow]] forApplication: NULL];
 }
        
 -(id) tableView: (NSTableView*)view objectValueForTableColumn: (NSTableColumn*) column row: (int) index {
     NSParameterAssert(index >= 0 && index < [configs count]);
-       return [[configs objectAtIndex: index] name];
+       return [configs[index] name];
 }
 
 -(void) tableView: (NSTableView*) view setObjectValue:obj forTableColumn:(NSTableColumn*) col row: (int)index {
     NSParameterAssert(index >= 0 && index < [configs count]);
        /* ugly hack so stringification doesn't fail */
        NSString* newName = [(NSString*)obj stringByReplacingOccurrencesOfString: @"~" withString: @""];
-       [(Config*)[configs objectAtIndex: index] setName: newName];
+       [(Config*)configs[index] setName: newName];
        [targetController refreshConfigsPreservingSelection:YES];
        [tableView reloadData];
        [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged];
 }
 
 -(BOOL)tableView: (NSTableView*)view shouldEditTableColumn: (NSTableColumn*) column row: (int) index {
-       return ![[configs objectAtIndex: index] protect];
+       return ![configs[index] protect];
 }      
 
 -(Config*) currentConfig {
        NSMutableArray* ary = [[NSMutableArray alloc] init];
        for(Config* config in configs) {
                NSMutableDictionary* cfgInfo = [[NSMutableDictionary alloc] init];
-               [cfgInfo setObject:[config name] forKey:@"name"];
+               cfgInfo[@"name"] = [config name];
                NSMutableDictionary* cfgEntries = [[NSMutableDictionary alloc] init];
                for(id key in [config entries]) {
-                       [cfgEntries setObject:[[[config entries]objectForKey:key]stringify] forKey: key];
+                       cfgEntries[key] = [[config entries][key]stringify];
                }
-               [cfgInfo setObject: cfgEntries forKey: @"entries"];
+               cfgInfo[@"entries"] = cfgEntries;
                [ary addObject: cfgInfo];
        }
-       [envelope setObject: ary forKey: @"configurationList"];
-       [envelope setObject: [NSNumber numberWithInt: [configs indexOfObject: [self currentNeutralConfig] ] ] forKey: @"selectedIndex"];
+       envelope[@"configurationList"] = ary;
+       envelope[@"selectedIndex"] = [NSNumber numberWithInt: [configs indexOfObject: [self currentNeutralConfig] ] ];
        return envelope;
 }
 -(void) loadAllFrom: (NSDictionary*) envelope{
        if(envelope == NULL)
                return;
-       NSArray* ary = [envelope objectForKey: @"configurationList"];
+       NSArray* ary = envelope[@"configurationList"];
        
        NSMutableArray* newConfigs = [[NSMutableArray alloc] init];
        // have to do two passes in case config1 refers to config2 via a TargetConfig
        for(int i=0; i<[ary count]; i++) {
                Config* cfg = [[Config alloc] init];
-               [cfg setName: [[ary objectAtIndex:i] objectForKey:@"name"]];            
+               [cfg setName: ary[i][@"name"]];         
                [newConfigs addObject: cfg];
        }
-       [[configs objectAtIndex:0] setProtect: YES];
+       [configs[0] setProtect: YES];
        for(int i=0; i<[ary count]; i++) {
-               NSDictionary* dict = [[ary objectAtIndex:i] objectForKey:@"entries"];
+               NSDictionary* dict = ary[i][@"entries"];
                for(id key in dict) {
-                       [[[newConfigs objectAtIndex:i] entries]
-                        setObject: [Target unstringify: [dict objectForKey: key] withConfigList: newConfigs]
-                        forKey: key];
+                       [newConfigs[i] entries][key] = [Target unstringify: dict[key] withConfigList: newConfigs];
                }
        }
        
        currentConfig = NULL;
        [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged];
        
-       int index = [[envelope objectForKey: @"selectedIndex"] intValue];
+       int index = [envelope[@"selectedIndex"] intValue];
     if (index < configs.count)
-        [self activateConfig: [configs objectAtIndex:index] forApplication: NULL];
+        [self activateConfig: configs[index] forApplication: NULL];
 }
 
 -(void) applicationSwitchedTo: (NSString*) name withPsn: (ProcessSerialNumber) psn {
        for(int i=0; i<[configs count]; i++) {
-               Config* cfg = [configs objectAtIndex:i];
+               Config* cfg = configs[i];
                if([[cfg name] isEqualToString: name]) {
                        [self activateConfig: cfg forApplication: &psn];
                        return;
index 6ac1e0d..9fbdbb6 100644 (file)
                        isa = XCBuildConfiguration;
                        buildSettings = {
                                ALWAYS_SEARCH_USER_PATHS = NO;
+                               ARCHS = "$(ARCHS_STANDARD_64_BIT)";
                                COMBINE_HIDPI_IMAGES = YES;
                                COPY_PHASE_STRIP = NO;
                                FRAMEWORK_SEARCH_PATHS = (
                                GCC_PREFIX_HEADER = Enjoy_Prefix.pch;
                                INFOPLIST_FILE = Info.plist;
                                INSTALL_PATH = "$(HOME)/Applications";
-                               MACOSX_DEPLOYMENT_TARGET = 10.6;
+                               MACOSX_DEPLOYMENT_TARGET = 10.6.8;
                                PRODUCT_NAME = Enjoy;
                        };
                        name = Debug;
                        isa = XCBuildConfiguration;
                        buildSettings = {
                                ALWAYS_SEARCH_USER_PATHS = NO;
+                               ARCHS = "$(ARCHS_STANDARD_64_BIT)";
                                COMBINE_HIDPI_IMAGES = YES;
                                DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
                                FRAMEWORK_SEARCH_PATHS = (
                                GCC_PREFIX_HEADER = Enjoy_Prefix.pch;
                                INFOPLIST_FILE = Info.plist;
                                INSTALL_PATH = "$(HOME)/Applications";
-                               MACOSX_DEPLOYMENT_TARGET = 10.6;
+                               MACOSX_DEPLOYMENT_TARGET = 10.6.8;
                                PRODUCT_NAME = Enjoy;
                        };
                        name = Release;
index e351996..2931464 100644 (file)
@@ -9,12 +9,9 @@
 
 - (id) initWithIndex: (int)newIndex {
        if(self = [super init]) {
-       subActions = [NSArray arrayWithObjects:
-               [[SubAction alloc] initWithIndex: 0 name: @"Low" base: self],
+       subActions = @[[[SubAction alloc] initWithIndex: 0 name: @"Low" base: self],
                [[SubAction alloc] initWithIndex: 1 name: @"High" base: self],
-        [[SubAction alloc] initWithIndex: 2 name: @"Analog" base: self],
-               nil
-       ];
+        [[SubAction alloc] initWithIndex: 2 name: @"Analog" base: self]];
                [subActions retain];
        index = newIndex;
        name = [[NSString alloc] initWithFormat: @"Axis %d", (index+1)];
@@ -23,8 +20,8 @@
 }
 
 -(id) findSubActionForValue: (IOHIDValueRef) value {
-    if ([[subActions objectAtIndex: 2] active]) {
-        return [subActions objectAtIndex: 2]; // TODO?
+    if ([subActions[2] active]) {
+        return subActions[2]; // TODO?
     }
     
     //Target* target = [[base->configsController currentConfig] getTargetForAction: [subActions objectAtIndex: 0]];
     double parsed = [self getRealValue: raw];
        
        if(parsed < -0.3) // fixed?!
-               return [subActions objectAtIndex: 0];
+               return subActions[0];
        else if(parsed > 0.3)
-               return [subActions objectAtIndex: 1];
+               return subActions[1];
        return NULL;
 }
 
 -(void) notifyEvent: (IOHIDValueRef) value {
     // Analog action is always active
-    [[subActions objectAtIndex: 2] setActive: true];
+    [subActions[2] setActive: true];
     
        int raw = IOHIDValueGetIntegerValue(value);
     double parsed = [self getRealValue: raw];
        
-       [[subActions objectAtIndex: 0] setActive: (parsed < -0.3)];
-       [[subActions objectAtIndex: 1] setActive: (parsed > 0.3)];
+       [subActions[0] setActive: (parsed < -0.3)];
+       [subActions[1] setActive: (parsed > 0.3)];
 }
 
 -(double) getRealValue: (int)value {
index 1ea30af..61241b9 100644 (file)
@@ -28,13 +28,10 @@ NO,  NO,  YES, NO , // W
 
 - (id) init {
        if(self = [super init]) {
-               subActions = [NSArray arrayWithObjects:
-                                         [[SubAction alloc] initWithIndex: 0 name: @"Up" base: self],
+               subActions = @[[[SubAction alloc] initWithIndex: 0 name: @"Up" base: self],
                                          [[SubAction alloc] initWithIndex: 1 name: @"Down" base: self],
                                          [[SubAction alloc] initWithIndex: 2 name: @"Left" base: self],
-                                         [[SubAction alloc] initWithIndex: 3 name: @"Right" base: self],
-                                         nil
-                                         ];
+                                         [[SubAction alloc] initWithIndex: 3 name: @"Right" base: self]];
                [subActions retain];
                name = @"Hat switch";
        }
@@ -46,34 +43,34 @@ NO,  NO,  YES, NO , // W
        if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 7) {
                // 8-way
                switch(parsed) {
-                       case 0: return [subActions objectAtIndex: 0];
-                       case 4: return [subActions objectAtIndex: 1];
-                       case 6: return [subActions objectAtIndex: 2];
-                       case 2: return [subActions objectAtIndex: 3];
+                       case 0: return subActions[0];
+                       case 4: return subActions[1];
+                       case 6: return subActions[2];
+                       case 2: return subActions[3];
                }
        } else  if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 8) {
                // 8-way
                switch(parsed) {
-                       case 1: return [subActions objectAtIndex: 0];
-                       case 5: return [subActions objectAtIndex: 1];
-                       case 7: return [subActions objectAtIndex: 2];
-                       case 3: return [subActions objectAtIndex: 3];
+                       case 1: return subActions[0];
+                       case 5: return subActions[1];
+                       case 7: return subActions[2];
+                       case 3: return subActions[3];
                }
        } else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 3) {
                        // 4-way
                switch(parsed) {
-                       case 0: return [subActions objectAtIndex: 0];
-                       case 2: return [subActions objectAtIndex: 1];
-                       case 3: return [subActions objectAtIndex: 2];
-                       case 1: return [subActions objectAtIndex: 3];
+                       case 0: return subActions[0];
+                       case 2: return subActions[1];
+                       case 3: return subActions[2];
+                       case 1: return subActions[3];
                }
        } else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 4) {
                // 4-way
                switch(parsed) {
-                       case 1: return [subActions objectAtIndex: 0];
-                       case 3: return [subActions objectAtIndex: 1];
-                       case 4: return [subActions objectAtIndex: 2];
-                       case 2: return [subActions objectAtIndex: 3];
+                       case 1: return subActions[0];
+                       case 3: return subActions[1];
+                       case 4: return subActions[2];
+                       case 2: return subActions[3];
                }
        }
        return NULL;
@@ -88,7 +85,7 @@ NO,  NO,  YES, NO , // W
        }
        BOOL* activeSubactions = (size == 8) ? active_eightway : active_fourway;
        for(int i=0; i<4; i++)
-               [[subActions objectAtIndex: i] setActive: activeSubactions[parsed * 4 + i]];
+               [subActions[i] setActive: activeSubactions[parsed * 4 + i]];
 }
 
 @end
index 8fa6791..fd08ee6 100644 (file)
@@ -48,7 +48,7 @@
        int axes = 0;
        
        for(int i=0; i<[elements count]; i++) {
-               IOHIDElementRef element = (IOHIDElementRef)[elements objectAtIndex: i];
+               IOHIDElementRef element = (IOHIDElementRef)elements[i];
                int type = IOHIDElementGetType(element);
                int usage = IOHIDElementGetUsage(element);
                int usagePage = IOHIDElementGetUsagePage(element);
@@ -96,8 +96,8 @@
 
 - (JSAction*) findActionByCookie: (void*) cookie {
        for(int i=0; i<[children count]; i++)
-               if([[children objectAtIndex:i]cookie] == cookie)
-                       return (JSAction*)[children objectAtIndex:i];
+               if([children[i]cookie] == cookie)
+                       return (JSAction*)children[i];
        return NULL;
 }
 
index 1bf5b43..6b748df 100644 (file)
@@ -23,7 +23,7 @@
 
 -(void) finalize {
        for(int i=0; i<[joysticks count]; i++) {
-               [[joysticks objectAtIndex:i] invalidate];
+               [joysticks[i] invalidate];
        }
        IOHIDManagerClose(hidManager, kIOHIDOptionsTypeNone);
        CFRelease(hidManager);
@@ -33,8 +33,8 @@
 static NSMutableDictionary* create_criterion( UInt32 inUsagePage, UInt32 inUsage )
 {
        NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
-       [dict setObject: [NSNumber numberWithInt: inUsagePage] forKey: (NSString*)CFSTR(kIOHIDDeviceUsagePageKey)];
-       [dict setObject: [NSNumber numberWithInt: inUsage] forKey: (NSString*)CFSTR(kIOHIDDeviceUsageKey)];
+       dict[(NSString*)CFSTR(kIOHIDDeviceUsagePageKey)] = [NSNumber numberWithInt: inUsagePage];
+       dict[(NSString*)CFSTR(kIOHIDDeviceUsageKey)] = [NSNumber numberWithInt: inUsage];
        return dict;
 } 
 
@@ -74,7 +74,7 @@ void input_callback(void* inContext, IOReturn inResult, void* inSender, IOHIDVal
                [mainAction notifyEvent: value];
                NSArray* subactions = [mainAction subActions];
                if(!subactions)
-                       subactions = [NSArray arrayWithObject:mainAction];
+                       subactions = @[mainAction];
                for(id subaction in subactions) {
                        Target* target = [[self->configsController currentConfig] getTargetForAction:subaction];
                        if(!target)
@@ -121,7 +121,7 @@ int findAvailableIndex(id list, Joystick* js) {
        for(int index=0;;index++) {
                available = YES;
                for(int i=0; i<[list count]; i++) {
-                       js2 = [list objectAtIndex: i];
+                       js2 = list[i];
                        if([js2 vendorId] == [js vendorId] && [js2 productId] == [js productId] && [js index] == index) {
                                available = NO;
                                break;
@@ -169,12 +169,9 @@ void remove_callback(void* inContext, IOReturn inResult, void* inSender, IOHIDDe
 
 -(void) setup {
     hidManager = IOHIDManagerCreate( kCFAllocatorDefault, kIOHIDOptionsTypeNone);
-       NSArray *criteria = [NSArray arrayWithObjects: 
-                create_criterion(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick),
+       NSArray *criteria = @[create_criterion(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick),
                 create_criterion(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad),
-         create_criterion(kHIDPage_GenericDesktop, kHIDUsage_GD_MultiAxisController),
-         //create_criterion(kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard),
-       nil];
+         create_criterion(kHIDPage_GenericDesktop, kHIDUsage_GD_MultiAxisController)];
        
        IOHIDManagerSetDeviceMatchingMultiple(hidManager, (CFArrayRef)criteria);
     
@@ -234,13 +231,13 @@ void remove_callback(void* inContext, IOReturn inResult, void* inSender, IOHIDDe
 
 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item {
        if(item == nil) 
-               return [joysticks objectAtIndex: index];
+               return joysticks[index];
 
        if([item isKindOfClass: [Joystick class]])
-               return [[item children] objectAtIndex: index];
+               return [item children][index];
        
        if([item isKindOfClass: [JSAction class]]) 
-               return [[item subActions] objectAtIndex:index];
+               return [item subActions][index];
 
        return NULL;
 }
index ec2d6a1..052f01a 100644 (file)
--- a/Target.m
+++ b/Target.m
@@ -10,7 +10,7 @@
 +(Target*) unstringify: (NSString*) str withConfigList: (NSArray*) configs {
        NSArray* components = [str componentsSeparatedByString:@"~"];
        NSParameterAssert([components count]);
-       NSString* typeTag = [components objectAtIndex:0];
+       NSString* typeTag = components[0];
        if([typeTag isEqualToString:@"key"])
                return [TargetKeyboard unstringifyImpl:components];
        if([typeTag isEqualToString:@"cfg"])
index dae7786..f62755d 100644 (file)
 
 +(TargetConfig*) unstringifyImpl: (NSArray*) comps withConfigList: (NSArray*) configs {
        NSParameterAssert([comps count] == 2);
-       NSString* name = [comps objectAtIndex: 1];
+       NSString* name = comps[1];
        TargetConfig* target = [[TargetConfig alloc] init];
        for(int i=0; i<[configs count]; i++)
-               if([[[configs objectAtIndex:i] name] isEqualToString:name]) {
-                       [target setConfig: [configs objectAtIndex:i]];
+               if([[configs[i] name] isEqualToString:name]) {
+                       [target setConfig: configs[i]];
                        return target;
                }
        NSLog(@"Warning: couldn't find matching config to restore from: %@",name);
index 3442a61..9f85fd9 100644 (file)
@@ -47,7 +47,7 @@
                case 2:
                {
                        TargetConfig* c = [[TargetConfig alloc] init];
-                       [c setConfig: [[configsController configs] objectAtIndex: [configPopup indexOfSelectedItem]]];
+                       [c setConfig: [configsController configs][[configPopup indexOfSelectedItem]]];
                        return c;
                }
         case 3: {
        NSArray* configs = [configsController configs];
        [configPopup removeAllItems];
        for(int i=0; i<[configs count]; i++) {
-               [configPopup addItemWithTitle: [[configs objectAtIndex:i]name]];
+               [configPopup addItemWithTitle: [configs[i]name]];
        }
        if(preserve)
                [configPopup selectItemAtIndex:initialIndex];
index 40661b8..f171a50 100644 (file)
@@ -16,8 +16,8 @@
 +(TargetKeyboard*) unstringifyImpl: (NSArray*) comps {
        NSParameterAssert([comps count] == 3);
        TargetKeyboard* target = [[TargetKeyboard alloc] init];
-       [target setVk: [[comps objectAtIndex:1] integerValue]];
-       [target setDescr: [comps objectAtIndex:2]];
+       [target setVk: [comps[1] integerValue]];
+       [target setDescr: comps[2]];
        return target;
 }
 
index 7429874..172f740 100644 (file)
@@ -19,7 +19,7 @@
 +(TargetMouseBtn*) unstringifyImpl: (NSArray*) comps {
        NSParameterAssert([comps count] == 2);
        TargetMouseBtn* target = [[TargetMouseBtn alloc] init];
-       [target setWhich: [[comps objectAtIndex:1] integerValue]];
+       [target setWhich: [comps[1] integerValue]];
        return target;
 }
 
index 8cf09d2..86dd736 100644 (file)
@@ -23,7 +23,7 @@
 +(TargetMouseMove*) unstringifyImpl: (NSArray*) comps {
        NSParameterAssert([comps count] == 2);
        TargetMouseMove* target = [[TargetMouseMove alloc] init];
-       [target setDir: [[comps objectAtIndex:1] integerValue]];
+       [target setDir: [comps[1] integerValue]];
        return target;
 }
 
index a1cca9c..be64f7a 100644 (file)
@@ -19,7 +19,7 @@
 +(TargetMouseScroll*) unstringifyImpl: (NSArray*) comps {
        NSParameterAssert([comps count] == 2);
        TargetMouseScroll* target = [[TargetMouseScroll alloc] init];
-       [target setHowMuch: [[comps objectAtIndex:1] integerValue]];
+       [target setHowMuch: [comps[1] integerValue]];
        return target;
 }