Просмотр исходного кода

use Objective-C 2.0 subscripting for dictionaries

Dan Loewenherz лет назад: 10
Родитель
Сommit
29a45aa02d

+ 1 - 1
Classes/ExplorerToolbar/FLEXExplorerViewController.m

@@ -333,7 +333,7 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
     if (indexOfView != NSNotFound) {
         UIView *view = self.viewsAtTapPoint[indexOfView];
         NSValue *key = [NSValue valueWithNonretainedObject:view];
-        UIView *outline = [self.outlineViewsForVisibleViews objectForKey:key];
+        UIView *outline = self.outlineViewsForVisibleViews[key];
         if (outline) {
             outline.frame = [self frameInLocalCoordinatesForView:view];
         }

+ 5 - 5
Classes/GlobalStateExplorers/FLEXLiveObjectsTableViewController.m

@@ -100,11 +100,11 @@ static const NSInteger kFLEXLiveObjectsSortByCountIndex = 1;
     
     NSUInteger totalCount = 0;
     for (NSString *className in self.allClassNames) {
-        totalCount += [[self.instanceCountsForClassNames objectForKey:className] unsignedIntegerValue];
+        totalCount += [self.instanceCountsForClassNames[className] unsignedIntegerValue];
     }
     NSUInteger filteredCount = 0;
     for (NSString *className in self.filteredClassNames) {
-        filteredCount += [[self.instanceCountsForClassNames objectForKey:className] unsignedIntegerValue];
+        filteredCount += [self.instanceCountsForClassNames[className] unsignedIntegerValue];
     }
     
     if (filteredCount == totalCount) {
@@ -154,8 +154,8 @@ static const NSInteger kFLEXLiveObjectsSortByCountIndex = 1;
         self.filteredClassNames = [self.filteredClassNames sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
     } else if (self.searchBar.selectedScopeButtonIndex == kFLEXLiveObjectsSortByCountIndex) {
         self.filteredClassNames = [self.filteredClassNames sortedArrayUsingComparator:^NSComparisonResult(NSString *className1, NSString *className2) {
-            NSNumber *count1 = [self.instanceCountsForClassNames objectForKey:className1];
-            NSNumber *count2 = [self.instanceCountsForClassNames objectForKey:className2];
+            NSNumber *count1 = self.instanceCountsForClassNames[className1];
+            NSNumber *count2 = self.instanceCountsForClassNames[className2];
             // Reversed for descending counts.
             return [count2 compare:count1];
         }];
@@ -189,7 +189,7 @@ static const NSInteger kFLEXLiveObjectsSortByCountIndex = 1;
     }
     
     NSString *className = self.filteredClassNames[indexPath.row];
-    NSNumber *count = [self.instanceCountsForClassNames objectForKey:className];
+    NSNumber *count = self.instanceCountsForClassNames[className];
     cell.textLabel.text = [NSString stringWithFormat:@"%@ (%ld)", className, (long)[count integerValue]];
     
     return cell;

+ 1 - 1
Classes/Network/FLEXNetworkHistoryTableViewController.m

@@ -222,7 +222,7 @@
     [self updateBytesReceived];
     [self updateFilteredBytesReceived];
 
-    FLEXNetworkTransaction *transaction = [notification.userInfo objectForKey:kFLEXNetworkRecorderUserInfoTransactionKey];
+    FLEXNetworkTransaction *transaction = notification.userInfo[kFLEXNetworkRecorderUserInfoTransactionKey];
     NSArray *tableViews = @[self.tableView];
     if (self.searchController.searchResultsTableView) {
         tableViews = [tableViews arrayByAddingObject:self.searchController.searchResultsTableView];

+ 5 - 5
Classes/Network/FLEXNetworkRecorder.m

@@ -129,7 +129,7 @@ NSString *const kFLEXNetworkRecorderResponseCacheLimitDefaultsKey = @"com.flex.r
     NSDate *responseDate = [NSDate date];
 
     dispatch_async(self.queue, ^{
-        FLEXNetworkTransaction *transaction = [self.networkTransactionsForRequestIdentifiers objectForKey:requestID];
+        FLEXNetworkTransaction *transaction = self.networkTransactionsForRequestIdentifiers[requestID];
         if (!transaction) {
             return;
         }
@@ -144,7 +144,7 @@ NSString *const kFLEXNetworkRecorderResponseCacheLimitDefaultsKey = @"com.flex.r
 - (void)recordDataReceivedWithRequestID:(NSString *)requestID dataLength:(int64_t)dataLength
 {
     dispatch_async(self.queue, ^{
-        FLEXNetworkTransaction *transaction = [self.networkTransactionsForRequestIdentifiers objectForKey:requestID];
+        FLEXNetworkTransaction *transaction = self.networkTransactionsForRequestIdentifiers[requestID];
         if (!transaction) {
             return;
         }
@@ -159,7 +159,7 @@ NSString *const kFLEXNetworkRecorderResponseCacheLimitDefaultsKey = @"com.flex.r
     NSDate *finishedDate = [NSDate date];
 
     dispatch_async(self.queue, ^{
-        FLEXNetworkTransaction *transaction = [self.networkTransactionsForRequestIdentifiers objectForKey:requestID];
+        FLEXNetworkTransaction *transaction = self.networkTransactionsForRequestIdentifiers[requestID];
         if (!transaction) {
             return;
         }
@@ -215,7 +215,7 @@ NSString *const kFLEXNetworkRecorderResponseCacheLimitDefaultsKey = @"com.flex.r
 - (void)recordLoadingFailedWithRequestID:(NSString *)requestID error:(NSError *)error
 {
     dispatch_async(self.queue, ^{
-        FLEXNetworkTransaction *transaction = [self.networkTransactionsForRequestIdentifiers objectForKey:requestID];
+        FLEXNetworkTransaction *transaction = self.networkTransactionsForRequestIdentifiers[requestID];
         if (!transaction) {
             return;
         }
@@ -230,7 +230,7 @@ NSString *const kFLEXNetworkRecorderResponseCacheLimitDefaultsKey = @"com.flex.r
 - (void)recordMechanism:(NSString *)mechanism forRequestID:(NSString *)requestID
 {
     dispatch_async(self.queue, ^{
-        FLEXNetworkTransaction *transaction = [self.networkTransactionsForRequestIdentifiers objectForKey:requestID];
+        FLEXNetworkTransaction *transaction = self.networkTransactionsForRequestIdentifiers[requestID];
         if (!transaction) {
             return;
         }

+ 1 - 1
Classes/Network/FLEXNetworkTransactionDetailTableViewController.m

@@ -432,7 +432,7 @@ typedef UIViewController *(^FLEXNetworkDetailRowSelectionFuture)(void);
     NSMutableArray *rows = [NSMutableArray arrayWithCapacity:[dictionary count]];
     NSArray *sortedKeys = [[dictionary allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
     for (NSString *key in sortedKeys) {
-        NSString *value = [dictionary objectForKey:key];
+        NSString *value = dictionary[key];
         FLEXNetworkDetailRow *row = [[FLEXNetworkDetailRow alloc] init];
         row.title = key;
         row.detailText = [value description];

+ 1 - 1
Classes/Network/PonyDebugger/FLEXNetworkObserver.m

@@ -903,7 +903,7 @@ static char const * const kFLEXRequestIDKey = "kFLEXRequestIDKey";
 
 - (FLEXInternalRequestState *)requestStateForRequestID:(NSString *)requestID
 {
-    FLEXInternalRequestState *requestState = [self.requestStatesForRequestIDs objectForKey:requestID];
+    FLEXInternalRequestState *requestState = self.requestStatesForRequestIDs[requestID];
     if (!requestState) {
         requestState = [[FLEXInternalRequestState alloc] init];
         [self.requestStatesForRequestIDs setObject:requestState forKey:requestID];

+ 2 - 2
Classes/ObjectExplorers/FLEXDictionaryExplorerViewController.m

@@ -43,7 +43,7 @@
 
 - (NSString *)customSectionSubtitleForRowCookie:(id)rowCookie
 {
-    return [FLEXRuntimeUtility descriptionForIvarOrPropertyValue:[self.dictionary objectForKey:rowCookie]];
+    return [FLEXRuntimeUtility descriptionForIvarOrPropertyValue:self.dictionary[rowCookie]];
 }
 
 - (BOOL)customSectionCanDrillIntoRowWithCookie:(id)rowCookie
@@ -53,7 +53,7 @@
 
 - (UIViewController *)customSectionDrillInViewControllerForRowCookie:(id)rowCookie
 {
-    return [FLEXObjectExplorerFactory explorerViewControllerForObject:[self.dictionary objectForKey:rowCookie]];
+    return [FLEXObjectExplorerFactory explorerViewControllerForObject:self.dictionary[rowCookie]];
 }
 
 - (BOOL)shouldShowDescription

+ 1 - 1
Classes/ObjectExplorers/FLEXObjectExplorerFactory.m

@@ -50,7 +50,7 @@
         for (NSString *objectTypeString in explorerSubclassesForObjectTypeStrings) {
             Class objectClass = NSClassFromString(objectTypeString);
             if ([object isKindOfClass:objectClass]) {
-                explorerClass = [explorerSubclassesForObjectTypeStrings objectForKey:objectTypeString];
+                explorerClass = explorerSubclassesForObjectTypeStrings[objectTypeString];
                 break;
             }
         }

+ 5 - 5
Classes/Utility/FLEXKeyboardShortcutManager.m

@@ -64,8 +64,8 @@
                                    @" " : @"␠"};
     
     NSString *prettyKey = nil;
-    if (self.key && [keyMappings objectForKey:self.key]) {
-        prettyKey = [keyMappings objectForKey:self.key];
+    if (self.key && keyMappings[self.key]) {
+        prettyKey = keyMappings[self.key];
     } else {
         prettyKey = [self.key uppercaseString];
     }
@@ -207,16 +207,16 @@
         } else {
             FLEXKeyInput *exactMatch = [FLEXKeyInput keyInputForKey:unmodifiedInput flags:flags];
             
-            dispatch_block_t actionBlock = [self.actionsForKeyInputs objectForKey:exactMatch];
+            dispatch_block_t actionBlock = self.actionsForKeyInputs[exactMatch];
             
             if (!actionBlock) {
                 FLEXKeyInput *shiftMatch = [FLEXKeyInput keyInputForKey:modifiedInput flags:flags&(!UIKeyModifierShift)];
-                actionBlock = [self.actionsForKeyInputs objectForKey:shiftMatch];
+                actionBlock = self.actionsForKeyInputs[shiftMatch];
             }
             
             if (!actionBlock) {
                 FLEXKeyInput *capitalMatch = [FLEXKeyInput keyInputForKey:[unmodifiedInput uppercaseString] flags:flags];
-                actionBlock = [self.actionsForKeyInputs objectForKey:capitalMatch];
+                actionBlock = self.actionsForKeyInputs[capitalMatch];
             }
             
             if (actionBlock) {

+ 9 - 9
Classes/Utility/FLEXRuntimeUtility.m

@@ -49,7 +49,7 @@ const unsigned int kFLEXNumberOfImplicitArgs = 2;
 + (NSString *)typeEncodingForProperty:(objc_property_t)property
 {
     NSDictionary *attributesDictionary = [self attributesDictionaryForProperty:property];
-    return [attributesDictionary objectForKey:kFLEXUtilityAttributeTypeEncoding];
+    return attributesDictionary[kFLEXUtilityAttributeTypeEncoding];
 }
 
 + (BOOL)isReadonlyProperty:(objc_property_t)property
@@ -77,33 +77,33 @@ const unsigned int kFLEXNumberOfImplicitArgs = 2;
     NSMutableArray *attributesStrings = [NSMutableArray array];
     
     // Atomicity
-    if ([attributesDictionary objectForKey:kFLEXUtilityAttributeNonAtomic]) {
+    if (attributesDictionary[kFLEXUtilityAttributeNonAtomic]) {
         [attributesStrings addObject:@"nonatomic"];
     } else {
         [attributesStrings addObject:@"atomic"];
     }
     
     // Storage
-    if ([attributesDictionary objectForKey:kFLEXUtilityAttributeRetain]) {
+    if (attributesDictionary[kFLEXUtilityAttributeRetain]) {
         [attributesStrings addObject:@"strong"];
-    } else if ([attributesDictionary objectForKey:kFLEXUtilityAttributeCopy]) {
+    } else if (attributesDictionary[kFLEXUtilityAttributeCopy]) {
         [attributesStrings addObject:@"copy"];
-    } else if ([attributesDictionary objectForKey:kFLEXUtilityAttributeWeak]) {
+    } else if (attributesDictionary[kFLEXUtilityAttributeWeak]) {
         [attributesStrings addObject:@"weak"];
     } else {
         [attributesStrings addObject:@"assign"];
     }
     
     // Mutability
-    if ([attributesDictionary objectForKey:kFLEXUtilityAttributeReadOnly]) {
+    if (attributesDictionary[kFLEXUtilityAttributeReadOnly]) {
         [attributesStrings addObject:@"readonly"];
     } else {
         [attributesStrings addObject:@"readwrite"];
     }
     
     // Custom getter/setter
-    NSString *customGetter = [attributesDictionary objectForKey:kFLEXUtilityAttributeCustomGetter];
-    NSString *customSetter = [attributesDictionary objectForKey:kFLEXUtilityAttributeCustomSetter];
+    NSString *customGetter = attributesDictionary[kFLEXUtilityAttributeCustomGetter];
+    NSString *customSetter = attributesDictionary[kFLEXUtilityAttributeCustomSetter];
     if (customGetter) {
         [attributesStrings addObject:[NSString stringWithFormat:@"getter=%@", customGetter]];
     }
@@ -179,7 +179,7 @@ const unsigned int kFLEXNumberOfImplicitArgs = 2;
             for (NSString *attributeName in [attributePairs allKeys]) {
                 objc_property_attribute_t attribute;
                 attribute.name = [attributeName UTF8String];
-                attribute.value = [[attributePairs objectForKey:attributeName] UTF8String];
+                attribute.value = [attributePairs[attributeName] UTF8String];
                 attributes[attributeIndex++] = attribute;
             }
             

+ 1 - 1
Classes/Utility/FLEXUtility.m

@@ -251,7 +251,7 @@
             id value = [[components lastObject] stringByRemovingPercentEncoding];
 
             // Handle multiple entries under the same key as an array
-            id existingEntry = [queryDictionary objectForKey:key];
+            id existingEntry = queryDictionary[key];
             if (existingEntry) {
                 if ([existingEntry isKindOfClass:[NSArray class]]) {
                     value = [existingEntry arrayByAddingObject:value];

+ 2 - 2
Example/UICatalog/AAPLTextViewController.m

@@ -107,8 +107,8 @@
     NSTimeInterval animationDuration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
     
     // Convert the keyboard frame from screen to view coordinates.
-    CGRect keyboardScreenEndFrame = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
-    CGRect keyboardScreenBeginFrame = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
+    CGRect keyboardScreenEndFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
+    CGRect keyboardScreenBeginFrame = [userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue];
 
     CGRect keyboardViewEndFrame = [self.view convertRect:keyboardScreenEndFrame fromView:self.view.window];
     CGRect keyboardViewBeginFrame = [self.view convertRect:keyboardScreenBeginFrame fromView:self.view.window];