Created
October 1, 2012 21:05
-
-
Save C4Code/3814414 to your computer and use it in GitHub Desktop.
Basic Arrays
This file contains hidden or 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
// | |
// C4WorkSpace.m | |
// arrays | |
// | |
// Created by moi on 12-10-01. | |
// Copyright (c) 2012 moi. All rights reserved. | |
// | |
#import "C4WorkSpace.h" | |
@implementation C4WorkSpace { | |
} | |
-(void)setup { | |
[self cArray]; | |
[self nsArray]; | |
[self nsMutableArray]; | |
[self cArrayWithPoints]; | |
[self cString]; | |
} | |
-(void)cArray { | |
C4Log(@"cArray"); | |
int nums[10] = {9,8,7,6,5,4,3,2,1,0}; | |
for(int i = 0; i < 10; i ++) { | |
C4Log(@"%d",nums[i]); | |
} | |
C4Log(@"\n"); | |
} | |
-(void)nsArray { | |
C4Log(@"nsArray"); | |
NSArray *nums = [[NSArray alloc] initWithObjects: | |
[NSNumber numberWithInt:9], | |
[NSNumber numberWithInt:8], | |
[NSNumber numberWithInt:7], | |
[NSNumber numberWithInt:6], | |
[NSNumber numberWithInt:5], | |
[NSNumber numberWithInt:4], | |
[NSNumber numberWithInt:3], | |
[NSNumber numberWithInt:2], | |
[NSNumber numberWithInt:1], | |
[NSNumber numberWithInt:0], | |
nil]; | |
for(NSNumber *n in nums) { | |
C4Log(@"%d",[n intValue]); | |
} | |
} | |
-(void)nsMutableArray { | |
C4Log(@"nsMutableArray"); | |
NSMutableArray *nums = [[NSMutableArray alloc] initWithCapacity:0]; | |
for(int i = 0; i < 10; i++) { | |
NSNumber *n = [NSNumber numberWithInt:9-i]; | |
[nums addObject:n]; | |
} | |
for(int i = 0; i < 10; i++) { | |
NSNumber *n = [nums objectAtIndex:i]; | |
C4Log(@"%d",[n intValue]); | |
} | |
C4Log(@"\n"); | |
} | |
-(void)cArrayWithPoints { | |
C4Log(@"cArray with points"); | |
CGPoint points[3] = {CGPointZero, | |
CGPointMake(100, 100), | |
CGPointMake([C4Math randomInt:500], [C4Math randomInt:500])}; | |
for(int i = 0; i < 3; i ++) { | |
C4Log(@"{%4.2f,%4.2f}",points[i].x,points[i].y); | |
} | |
C4Log(@"\n"); | |
} | |
-(void)cString { | |
C4Log(@"cString"); | |
NSString *s = @"this is a string"; | |
const char *cString = [s UTF8String]; | |
for(int i = 0; i < s.length; i++){ | |
C4Log(@"%c",cString[i]); | |
} | |
C4Log(@"\n"); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment