`
qzww5324
  • 浏览: 37368 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

objective-C 笔记(一)

阅读更多

 

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    NSLog(@"Hello, objective-c! %d  %f",100,3.3);
	//printf("test");
    return (0);
}
 

1.import:作用如同include ,用于声明头文件 

 

#import <Foundation/Foundation.h>

2.NSLog():系统函数,作用类似printf,同样可以以%d的形式接收参数。

3.@ :在objective-c中 如果置于字符串前,表示该串为一个NSString元素,和NSLog函数一样同属于cocoa

4.函数返回值 return(0):同c一样返回0表示程序执行成功。

 

 

#import <Foundation/Foundation.h>

BOOL areIntsDifferent(int thing1,int thing2){
	if(thing1==thing2)
		return(NO);
	else
		return(YES);
}

NSString *boolString(BOOL yesNo){
	if(yesNo==YES)
		return (@"yes!");
	else
		return(@"no!");
}

BOOL areIntsDifferent_faulty(int thing1,int thing2){
	return (thing1-thing2);
}

int main (int argc, const char * argv[]) {
	BOOL aredifferent;
	//NSLog(@"test bool default value :%@",aredifferent);
	aredifferent=areIntsDifferent(4, 5);
    NSLog(@"are %d and %d different ? %@",4,5,boolString(aredifferent));
	//if(areIntsDifferent_faulty(3, 4)==YES)//"NO"
	if(areIntsDifferent_faulty(3, 4))
		NSLog(@"test other cond : yes");
	else
		NSLog(@"test other cond : no");
	
	//NSLog(@"test error: %@",areIntsDifferent_faulty(4,5));
    return 0;
}
 

 

5.BOOL类型:在objective-c可以用YES,NO来表示,YES定义为1,NO定义为0。不能将BOOL值与YES,NO直接比较。

6.%@ :表示接收一个NSString类型指针的参数

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics