How can I add a boolean value to a NSDictionary?

后端 未结 5 1745
长情又很酷
长情又很酷 2021-01-30 05:46

Well, for integers I would use NSNumber. But YES and NO aren\'t objects, I guess. A.f.a.i.k. I can only add objects to an NSDictionary, right?

5条回答
  •  再見小時候
    2021-01-30 06:47

    If you are declaring it as a literal and you are using clang v3.1 or above, you should use @NO / @YES if you are declaring it as a literal. E.g.

    NSMutableDictionary* foo = [@{ @"key": @NO } mutableCopy];
    foo[@"bar"] = @YES;
    

    For more info on that:

    http://clang.llvm.org/docs/ObjectiveCLiterals.html

提交回复
热议问题