object-c 基本语法

类型:

NSString

NSInteger

NSLong控制台输出

 

NSObject:对象

比较两个对象是否相等:

 

[cpp]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
 
  1. NSObject *object1 = [[NSObject alloc] init];  
  2. NSObject *object2 = obejct1;  
  3. if([object isEqual:object2])  
  4. {  
  5.     NSLong(@"is equal");  
  6. }  
  7. else  
  8. {  
  9.     NSLong(@"is not equal");  
  10. }  

 

 

判断一个string是否为空:

[cpp]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
 
  1. NSString *shortString  = @"HelloWorld";  
  2. if([shortString lengtg] == 0)  
  3. {  
  4.     NSLong(@"is empty string");  
  5. }  
  6. else  
  7. {  
  8.     NSLong(@"is not empty string ");  
  9. }  

 

循环结构,比如for:

 

[cpp]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
 
  1. int increment = 0;  
  2. for (increment = 0; increment < 100; increment++)  
  3. {  
  4.     NSLog(increment++);  
  5. }  

 

 

-(void) method : (int) arguments;

-为方法类型 +表示类方法

 

-(id) initWithAge:(int) _age identify:(int)_identify

方法名称为initWithAge,第一个参数是(int) _age,第二个参数是(int)_identify

identify其实是对_identify的一个说明,initWithAge对_age一个说明

 

方法的调用:

1.[类名或对象名 方法名];

2.对象名.方法名

 

[cpp]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
 
  1. NSString *s;  
  2. s = [[NSString alloc] initWithString:@Hello iphone4S];  
  3.   
  4.   
  5. Person *person = [Person alloc];  
  6. person = [person init];  
  7.   
  8. -(id) initWithAge:(int)_age identify:(int) _identify  
  9. {  
  10. if<
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值