[特別プログラマー]Foundationフレームワーク
4277 ワード
//
NSString *string2 = [NSString stringWithFormat:@"123"];
//
NSString *ptr = [string1 uppercaseString];
NSLog(@" :%@",ptr);
//
NSString *ptr1 = [string1 lowercaseString];
NSLog(@" :%@",ptr1);
// ,
NSString *ptr2 = [string1 capitalizedString];
NSLog(@" , :%@",ptr2);
//
NSLog(@" :%ld",[string1 compare:string2]);
2.可変文字列の作成と使用
//
NSMutableString *mutablestring = [NSMutableString stringWithCapacity:10];
[mutablestring appendString:@" , "];
NSLog(@"%@",mutablestring);
//
NSRange strRange = [mutablestring rangeOfString:@" "];
[mutablestring deleteCharactersInRange:strRange];
NSLog(@"%@",mutablestring);
3.可変配列の作成
NSArray *ac = [NSArray arrayWithObjects:@"jack",@"mill", nil];
4.可変配列の作成と使用
NSMutableArray *array = [NSMutableArray arrayWithObjects:@"mali",@"hire", nil];
[array addObject:@"halen"];
[array removeObjectAtIndex:1];
NSLog(@"%@",array);
5.列挙
NSArray *parent = @[@" ",@" "];
NSEnumerator *rator = [parent objectEnumerator];
id object;
while (object = [rator nextObject] ) {
NSLog(@"object:%@",object);
}
6.不変辞書
NSDictionary *directionary = @{@"t1":@" ",@"t2":@" "};
NSLog(@" :%@",[directionary objectForKey:@"t2"]);
7.可変辞書
NSArray *personvalue = @[@" ",@"25",@" "];
NSArray *personkey = @[@"name",@"age",@"location"]; NSMutableDictionary *dict2 = [NSMutableDictionary dictionaryWithObjects:personvalue forKeys: personkey];
NSLog(@"%@",dict2[@"name"]);
//
[dict2 addEntriesFromDictionary:@{@"ren":@" "}];
//
[dict2 removeObjectForKey:@"age"];
//
[dict2 setObject:@" " forKey:@"name"];
[dict2 setValue:@" " forKey:@"name"];
//
[dict2 removeAllObjects];
NSLog(@"%@",dict2);
8.構造体
CGPoint p1 = NSMakePoint(3, 6);
NSLog(@"%.2f %.2f",p1.x,p1.y);
CGSize s1 = NSMakeSize(10, 20);
NSLog(@"%2.f %2.f",s1.width,s1.height);
CGRect r1 = NSMakeRect(0,0,0,0);
r1.origin = p1;
r1.size = s1;
NSLog(@"%.2f %.2f %.2f %.2f",r1.origin.x,r1.origin.y,r1.size.width,r1.size.height);
CGRect r2 = NSMakeRect(0, 0, 50, 80);
NSLog(@"point(x:%.2f y:%.2f)
width:%.2f height:%.2f",r2.origin.x,r2.origin.y,r2.siz e.width,r2.size.height);
9.時間と構造体の使用
struct Date{
int year;
int month;
int day;
int hh;
int mm;
int ss;
};
struct Date d1 ={2015,05,19,18,14,50};
NSLog(@"%i/%i/%i %i:%i:%i",d1.year,d1.month,d1.day,d1.hh,d1.mm,d1.ss);
10.NSNumber
NSNumber *number1 = [NSNumber numberWithChar:'k'];
NSLog(@"%@",number1);
NSNumber *number2 = [NSNumber numberWithInt:32544];
NSLog(@"%@",number2);
number = @12345ul;
NSLog(@"%@",number);
number = @12345ll;
NSLog(@"%@",number);
number = @123.45f;
NSLog(@"%@",number);
number = @YES;
NSLog(@"%@",number);
unsigned int a=-12;
NSLog(@"%u",a);