oc语言的学习笔记整理:基本语法

//

//  main.m

//  oc基本语法

//

//  Created by lanou on 16/7/9.

//  Copyright © 2016年pingguo. All rights reserved.

//

#import

intmain(intargc,constchar* argv[]) {

@autoreleasepool{

// insert code here...

NSLog(@"Hello, World!");

//        oc基本语法

//整型

NSIntegera =10;

NSLog(@"a=%ld",a);

CGFloatb =2.3;

NSLog(@"b=%.2f",b);

BOOLflag =YES;

NSString*str=@"abcde";

NSLog(@"str=%@",str);

NSLog(@"str的长度=%ld",str.length);

if([strisEqualToString:@"abcde"]) {

NSLog(@"是的");

}

if([strhasPrefix:@"a"]) {

NSLog(@"前缀等于a");}

if([strhasSuffix:@"e"]) {

NSLog(@"后缀等于e");

}

NSString*str1=[NSStringstringWithFormat:@"%@++++",@"im"];

NSLog(@"str1=%@",str1);

}

return0;

}



//

//  main.m

//  oc基础语法2

//

//  Created by lanou on 16/7/9.

//  Copyright © 2016年pingguo. All rights reserved.

//

#import

intmain(intargc,constchar* argv[]) {

@autoreleasepool{

// insert code here...

NSLog(@"Hello, World!");

NSArray*array1=@[@"a",@"b",@"c",@"d"];

NSLog(@"array1=%@",array1);

NSLog(@"count=%ld",array1.count);

NSString*str = array1[0];

NSLog(@"str=%@",str);

NSMutableArray*mutableArray =[NSMutableArrayarrayWithObjects:@"1",@"2",@"3",@"4",nil];

NSLog(@"mutable Array=%@",mutableArray);

[mutableArrayaddObject:@"5"];

NSLog(@"已添加----%@",mutableArray);

[mutableArrayremoveObject:@"3"];

NSLog(@"已移除----%@",mutableArray);

NSDictionary*dict =@{@"key1":@"value1",@"key2":@"value2",@"key3":@"value3"};

NSLog(@"dict=%@",dict);

NSString*string=[dictobjectForKey:@"key1"];

NSLog(@"string=%@",string);

NSLog(@"allkeys=%@,allvalues=%@",dict.allKeys,dict.allValues);

}

return0;

}

你可能感兴趣的:(oc语言的学习笔记整理:基本语法)