NSNumber Literals

前端 未结 5 1684
南方客
南方客 2020-12-18 09:32

I am very new to Objective-C. I know C and C++ but Objective-C has quite the learning curve. Anyway, is there a shorter way (possibly by some kind of NSNumber literal if suc

5条回答
  •  天命终不由人
    2020-12-18 09:45

    Yes, just use one of the many helper functions such as numberWithInt::

    [Tyler setArms:[NSNumber numberWithInt:1]];
    

    The expression [NSNumber numberWithInt:1] is equivalent to [[[NSNumber alloc] initWithInt:1] autorelease], which is equivalent to [[[NSNumber alloc] autorelease] initWithInt:1]. The latter expression is extremely uncommon.

提交回复
热议问题