【Objective C Day 1】HelloTheWorld&BOOL Type

QFord:

First , I would like to introduce you a good tutorial : Learn Objective C on  Mac .

All materials I wrote here base on this book !(QFord@QQ.COM)

I : Hello, the world !

 

 

1:Xcode uses the .m extension to indicate a file that holds  Objective- C code

 

2: #import <Foundation/Foundation.h>

 Objective- C uses header files to hold the declarations of elements such as
structs, symbolic constants, and function prototypes. 

The #import <Foundation/Foundation.h> statement tells the compiler to look at the
Foundation.h header file in the Foundation framework.

 

3:NSLog just like printf in c ,but it  supports ouput NSString.

As you can see here , at sigh before a string ,it indicates a NSString . 

 

II :BOOL type

 

1:The areIntsDifferent() function

It  takes two integer parameters and returns a BOOL value. The syntax should be familiar to you from your C experience.

Objc has 2 BOOL value : YES & NO

 

 

2:The boolString() function

It  maps a numeric BOOL value to a string that’s readable by mere humans

Notice that the return type of boolString() is a pointer to an NSString.

 

3:The main() function

You can see that the two fives will replace the two %d format placeholders in our call to NSLog().

 

At the end of the string we’re giving to NSLog(), you see another at sign. This time, it’s %@.
What’s that all about? boolString() returns an NSString pointer. printf() has no idea
how to work with an NSString, so there is no a format specifier we can use. The makers of
NSLog() added the %@ format specifier to instruct NSLog() to take the appropriate argu-
ment, treat it as an NSString, use the characters from that string, and send it out to the
console.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值