objective-c - 如何向 NSDictionary 添加 bool 值?

好吧,对于整数,我会使用 NSNumber。但 YES 和 NO 不是对象,我猜。 AFAIK。我只能将对象添加到 NSDictionary,对吧?

我找不到任何 bool 值的包装类。有吗?

最佳答案

你使用 NSNumber。

它有 init... 和 number... 方法,它们接受 bool 值,就像它接受整数等一样。

来自 NSNumber class reference :

// Creates and returns an NSNumber object containing a 
// given value, treating it as a BOOL.
+ (NSNumber *)numberWithBool:(BOOL)value

和:

// Returns an NSNumber object initialized to contain a
// given value, treated as a BOOL.
- (id)initWithBool:(BOOL)value

和:

// Returns the receiver’s value as a BOOL.
- (BOOL)boolValue

https://stackoverflow.com/questions/903906/

相关文章:

objective-c - 未找到体系结构 i386 的符号

ios - 将 UIButton 字体大小调整为宽度

objective-c - #import 使用尖括号 < > 和引号 ""

ios - 将 Project-Swift.h 导入到 Objective-C 类中...找不到文件

objective-c - 警告 : "format not a string literal an

objective-c - Objective-C 中的 protected 方法

objective-c - 使用 -performSelector : vs. 只是调用方法

ios - 使用 `textField:shouldChangeCharactersInRange:

ios - 在 iOS 应用程序中在哪里存储全局常量?

ios - 如何使用 iOS 轻松调整/优化图像大小?