How can I add a boolean value to a NSDictionary?

后端 未结 5 1786
长情又很酷
长情又很酷 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:35

    As jcampbell1 pointed out, now you can use literal syntax for NSNumbers:

    NSDictionary *data = @{
                          // when you always pass same value
                          @"someKey" : @YES
                          // if you want to pass some boolean variable
                          @"anotherKey" : @(someVariable)
                          };
    

提交回复
热议问题