Created
February 13, 2014 00:08
-
-
Save EdSancha/8967185 to your computer and use it in GitHub Desktop.
Fast Enumeration Best Techniques following Nick Lockwood article: http://iosdevelopertips.com/objective-c/high-performance-collection-looping-objective-c.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fast Enumeration Best Techniques: | |
// Following Nick Lockwood article: http://iosdevelopertips.com/objective-c/high-performance-collection-looping-objective-c.html?utm_source=iOSDevTips&utm_campaign=wordtwit&utm_medium=twitter | |
// NSArray Fast Enumeration | |
NSMutableArray *array; | |
for (<#type *object#> in array) { | |
<#statements#> | |
} | |
for (<#type *object#> in [array reverseObjectEnumerator]) { | |
<#statements#> | |
} | |
// Need index or modify array | |
NSUInteger count = [array count]; | |
for (NSUInteger i = 0; count; i++) { | |
<#statements#> | |
} | |
// if your code might benefit from parallel execution | |
[array enumerateObjectsWithOptions:NSEnumerationConcurrent | |
usingBlock:^(id obj, NSUInteger idx, BOOL *stop) { | |
<#statements#> | |
}]; | |
// NSSet Fast Enumeration | |
NSSet *set; | |
for (<#type *object#> in set) { | |
<#statements#> | |
} | |
// Need modify set | |
for (<#type *object#> in [set reverseObjectEnumerator]) { | |
<#statements#> | |
} | |
// if your code might benefit from parallel execution | |
[set enumerateObjectsWithOptions:NSEnumerationConcurrent | |
usingBlock:^(id obj, NSUInteger idx, BOOL *stop) { | |
<#statements#> | |
}]; | |
// NSDictionary Fast Enumeration | |
NSDictionary *dictionary; | |
[dictionary enumerateKeysAndObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { | |
<#statements#> | |
}]; | |
// Need modify dictionary | |
for (id key in [dictionary allKeys]) { | |
<#statements#> | |
} | |
// if your code might benefit from parallel execution | |
[dictionary enumerateKeysAndObjectsWithOptions:NSEnumerationConcurrent | |
usingBlock:^(id obj, NSUInteger idx, BOOL *stop) { | |
<#statements#> | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment