#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
//////////////////////////////字符串////////////////////////////
//字符串实例化
//initWithString:"lgfdftkk"
//initWithFormat:@"%@ %d", 't', '2';
//字符串连接
NSString *value_1 = @"lanou";
NSString *value_2 = @"3g";
NSString *result = nil;
result = [value_1 stringByAppendingString:value_2];
NSString *result2 = nil;
result2 = [value_2 stringByAppendingFormat:@"%@", value_1];
//子串
// NSRange range = NSMakeRange(8, 2);
// = [psn substringWithRange:range];
// = [psn substringFromIndex:range.location + range.length + 1];//1是空格z占用的位置
//转换
NSString *value = @"2";
int intValue = [value intValue];
NSLog(@"%d", intValue);
//改变大小写
NSString *mixString = @"abCdE";
NSString *lowwer = [mixString lowercaseString];
NSString *upper = [mixString uppercaseString];
NSLog(@"lower:%@", lowwer);
NSLog(@"upper:%@", upper);
//比较
NSString *value1 = @"abc";
NSString *value2 = @"ABC";
BOOL isEqual = [value1 isEqualToString:value2];
NSLog(@"%d", isEqual);
NSComparisonResult result3 = [value1 compare:value2];
NSLog(@"%d", result3);
/////////////////////////////////////数组//////////////////////////////
//NSArray
//实例化。。nil
NSArray *array = [[NSArray alloc] initWithObjects:@"a", @"b", @"c", nil];
NSLog(@"%@", array);
//获取某个元素
NSString *theLastItem = [array lastObject];
NSLog(@"%@", theLastItem);
//获取其他
NSString *theOtherItem = [array objectAtIndex:0];
NSLog(@"%@", theOtherItem);
NSArray *anyarray = [array arrayByAddingObject:@"d"];
NSLog(@"angarray = %@", anyarray);
NSLog(@"%@", array);
//isEqualToArray
//removeall
//NSMutableArray
NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
[mutableArray addObject:@"1"];
[mutableArray addObject:@"2"];
NSLog(@"%@", mutableArray);
[mutableArray addObject:@"3"];
NSLog(@"%@", mutableArray);
/////////////////////////////////字典////////////////////////////////
//实例化NSDictionary
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"value1", @"keya", @"value2", @"keyb", nil];
//在实例化不可变字典对象时, 如果在参数的前边已经包含了某一个关键字key,那么在后边出现的相同多关键字则不会添加到字典容器内
NSLog(@"%@", dictionary);//关键字不可重复,值可以
NSString *string = [dictionary objectForKey:@"keya"];
NSLog(@"%@", string);
//NSMutableDictionary
NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] init];
[mutableDictionary setObject:@"1" forKey:@"a"];
[mutableDictionary setObject:@"2" forKey:@"b"];
NSLog(@"%@", mutableDictionary);
//
[mutableDictionary setObject:@"3" forKey:@"a"];
NSLog(@"%@", mutableDictionary);
//在对可变字典对象添加元素时,,如果在字典对象内已经包含了对象的关键字,那么可变字典对象内该关键字的值则会发生变化(覆盖)
//////////////////////////////////不可变集合////////////////////////////
NSSet *set = [[NSSet alloc] initWithObjects:@"1", @"2", @"3", nil];
NSLog(@"%@", set);//{()}里面无序 //121(x),在集合里是不允许出现重复对象
//获取集合内的任意一个对象
NSString *item = [set anyObject];
NSLog(@"item:%@", item);
//////////////////////////////////可变集合/////////////////////////////
//实例化
NSMutableSet *mutableSet = [[NSMutableSet alloc] init];
[mutableSet addObject:@"1"];
[mutableSet addObject:@"2"];
NSLog(@"%@", mutableSet);//不允许重复
////////////////////////////遍历3种容器内的所有元素//////////////////////
//快速枚举for...in...
//实例化数组对象
NSMutableArray *mutable= [[NSMutableArray alloc] init];
[mutable addObject:@"abc"];
[mutable addObject:@"qwe"];
[mutable addObject:@"ert"];
for (NSInteger index = 0; index < [mutable count]; index++) {
NSString *stringItem = [mutable objectAtIndex:index];
NSLog(@"%ld:%@", index, stringItem);
}
for (NSString *item in mutable) { //数据类型。。。集合
NSLog(@"%@", item);
}
///////////////////////////////collection//////////////////////////////
//自己负责+1, -1;
return 0;
}
142

被折叠的 条评论
为什么被折叠?



