OC_变量类型

半年前错误决定浪费了这么多宝贵的时间,现在还是老老实实搞开发,从头做起一步一个脚印,ios开发虽然现在潮水退去,不过毕竟现在不是热门岗位,这段时间我调查了很多,移动端好像确实竞争不是很激烈,如果我从现在开始搞半年,我有信心能找到好工作,毕竟算法有一些考虑硬性条件,例如实验室资源科班等限制因素,硕士也都知道其实会议啥的有一定的技巧,最关键的就是实验室氛围和实验室条件,我这周围全是在搞电力电子,就我一个在搞算法编程,确实这些硬性条件难以达到标准,在半年后的秋招肯定要碰壁,不如从现在开始搞开发,开发的好处就是没什么硬性指标,只要我努力学把技术提升上去,我不觉得我会比别人差多少,加油吧,虽然QQ群里有人说我这是49年入国军,我也要坚持下去,坚持我的选择!
——————————————————————————
字符串的替代符为:@,且每个字符串前面都要加@,而且字符串的变量为指针形式

//字符串 对象类型 
    NSLog(@"hello,world");
    NSString * mystring = @"dajiahao";
    NSLog(@"myfirst:%@", mystring);
//字符串拼接
    NSString * mystring1 = @"hello";
    NSString * mystring2 = @"world";
    NSString * mystring3 = [NSString stringWithFormat:@"%@ %@",mystring1,mystring2];
    NSLog(@"mystring3:%@",mystring3);
//字符串截取
    NSString * mystring4 = [mystring3 substringFromIndex:5];
    NSLog(@"substring3:%@",mystring4);
//字符串替换
    NSString * mystring5 = [mystring3 stringByReplacingOccurrencesOfString:@"world" withString:@"haha"];
    NSLog(@"%@", mystring5);
//字符
    char mychar = 'c';
    NSLog(@"char:%c",mychar);

注意整数的替代符是 %ld

//整数
    NSUInteger myint1 = 10;
    NSLog(@"myint1:%ld",myint1);

float小数点后7位,double小数点后15位

//小数
    CGFloat myfloat = 3.13132123;
    double mydouble = 3.13132123;
    NSLog(@"myfloat:%f,%f",myfloat,mydouble);

数组不可变数组,长度不能改变,只能存放对象类型的值,例如字符串,不能保存整型这种,需要转换成对象类型才行。

//数组 不能存放inter这种非对象类型,不可改变
    NSArray *arr = [[NSArray alloc] initWithObjects:@"a",@"b",@"c", nil];
    NSLog(@"%@,%@,%@",arr[0],arr[1],arr[2]);
//可变数组 不能存放inter这种非对象类型,不可改变
    NSMutableArray *muarr = [NSMutableArray array];
    [muarr addObject:@"a"];//添加
    [muarr addObject:@"b"];
    [muarr addObject:@"c"];
    NSLog(@"%@,%@,%@",muarr[0],muarr[1],muarr[2]);
    [muarr removeObject:0];
    NSLog(@"%@,%@",muarr[0],muarr[1]);
//字典
    NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"value1",@"key1",@"value2",@"key2", nil];
    NSLog(@"%@",[dict objectForKey:@"key1"]);
    NSLog(@"%@",[dict objectForKey:@"key2"]);
    
    NSDictionary *dict1 = [[NSDictionary alloc] initWithObjects:@[@"value1",@"value2"] forKeys:@[@"key1",@"key2"]];
    NSLog(@"%@",[dict objectForKey:@"key1"]);
    NSLog(@"%@",[dict objectForKey:@"key2"]);
//可变字典
    NSMutableDictionary *mudict = [[NSMutableDictionary alloc] init];
    [mudict setObject:@"value1" forKey:@"key1"];//添加
    [mudict setObject:@"value2" forKey:@"key2"];
    NSLog(@"%@",[dict objectForKey:@"key1"]);
    NSLog(@"%@",[dict objectForKey:@"key2"]);
    [mudict removeObjectForKey:@"key2"];//删除

再加个句式,OC和python等一样,循环语句也可以用for in结构

//循环语句
    NSArray *arr = [[NSArray alloc] initWithObjects:@"a",@"b",@"c", nil];
    for (NSString *value in arr){
        NSLog(@"%@", value);
    }

猜你喜欢

转载自blog.csdn.net/weixin_43554642/article/details/88556663