ios developer tiny share-20161011

本文介绍了Objective-C中定义的基本类型,包括BOOL类型的使用及其逻辑等价性,以及平台特定的数值类型如NSInteger和NSUInteger的区别与应用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天讲Objective-C中定义的除了C语言定义的以外的基本类型。


Objective-C Defines Additional Primitive Types
The BOOL scalar type is defined in Objective-C to hold a Boolean value, which is either YES or NO. As you might expect, YES is logically equivalent to true and 1, while NO is equivalent to false and 0.

Many parameters to methods on Cocoa and Cocoa Touch objects also use special scalar numeric types, such as NSInteger or CGFloat.

For example, the NSTableViewDataSource and UITableViewDataSource protocols (described in the previous chapter) both have methods requesting the number of rows to display:

@protocol NSTableViewDataSource <NSObject>
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView;
...
@end

These types, like NSInteger and NSUInteger, are defined differently depending on the target architecture. When building for a 32-bit environment (such as for iOS), they are 32-bit signed and unsigned integers respectively; when building for a 64-bit environment (such as for the modern OS X runtime) they are 64-bit signed and unsigned integers respectively.

It’s best practice to use these platform-specific types if you might be passing values across API boundaries (both internal and exported APIs), such as arguments or return values in method or function calls between your application code and a framework.

For local variables, such as a counter in a loop, it’s fine to use the basic C types if you know that the value is within the standard limits.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值