Created
June 6, 2014 22:34
-
-
Save RobertHaworth/5f2b07da1ce444e7ee04 to your computer and use it in GitHub Desktop.
Progressive track of new developers iterating NSArray in Obj-C.
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
// | |
// AppDelegate.m | |
// testApplication | |
// | |
// Created by Robert Haworth on 6/6/14. | |
// Copyright (c) 2014 Robert Haworth. All rights reserved. | |
// | |
#import "AppDelegate.h" | |
@interface AppDelegate () | |
@end | |
@implementation AppDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | |
// Override point for customization after application launch. | |
self.window.backgroundColor = [UIColor whiteColor]; | |
[self.window makeKeyAndVisible]; | |
NSArray *scenes = @[@"Act 1 Scene 1: Verona, A public place", | |
@"Act 1 Scene 2: Capulet's mansion", | |
@"Act 1 Scene 3: A room in Capulet's mansion", | |
@"Act 1 Scene 4: A street outside Capulet's mansion", | |
@"Act 1 Scene 5: The Great Hall in Capulet's mansion", | |
@"Act 2 Scene 1: Outside Capulet's mansion", | |
@"Act 2 Scene 2: Capulet's orchard", | |
@"Act 2 Scene 3: Outside Frair Lawrence's cell", | |
@"Act 2 Scene 4: A street in Verona", | |
@"Act 2 Scene 5: Capulet's mansion", | |
@"Act 2 Scene 6: Frair Lawrence's cell"]; | |
//Level-0 | |
// | |
int indexTest = 0; | |
for (int i = 0; i < 11; i++) { | |
if ([scenes[i] hasPrefix:@"Act 1"]) { | |
indexTest++; | |
} | |
} | |
NSLog(@"Act 1 has %i scenes", indexTest); | |
// | |
// | |
[self levelOne:scenes]; | |
[self levelTwo:scenes]; | |
[self levelThree:scenes]; | |
[self levelFour:scenes]; | |
return YES; | |
} | |
-(void)levelOne:(NSArray *)array | |
{ | |
int indexTest = 0; | |
for (int i = 0; i < 11; i++) { | |
if ([array[i] hasPrefix:@"Act 1"]) { | |
indexTest++; | |
} | |
} | |
NSLog(@"Act 1 has %i scenes", indexTest); | |
} | |
- (void)levelTwo:(NSArray *)scenes | |
{ | |
int indexTest = 0; | |
for (int integer = 0; integer < [scenes count]; integer++) { | |
if ([scenes[integer] hasPrefix:@"Act 1"]) { | |
indexTest++; | |
} | |
} | |
NSLog(@"Act 1 has %i scenes", indexTest); | |
} | |
- (void)levelThree:(NSArray *)scenes | |
{ | |
int actOneCount = 0; | |
for (NSString *scene in scenes) { | |
if ([scene hasPrefix:@"Act 1"]) { | |
actOneCount++; | |
} | |
} | |
NSLog(@"Act 1 has %i scenes", actOneCount); | |
} | |
- (void)levelFour:(NSArray *)scenes | |
{ | |
__block int actTwoCount = 0; | |
[scenes enumerateObjectsUsingBlock:^(NSString *scene, NSUInteger idx, BOOL *stop) { | |
if ([scene hasPrefix:@"Act 2"]) { | |
actTwoCount++; | |
} | |
}]; | |
NSLog(@"while Act 2 has: %i scenes.", actTwoCount); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment