NSNumber文字 [英] NSNumber Literals
问题描述
我对Objective-C非常陌生.我知道C和C ++,但是Objective-C有相当的学习曲线.无论如何,有没有一种较短的方法(如果存在的话,可以使用某种NSNumber文字)来编写以下内容:
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 such exists) to write the following:
[Tyler setArms:[[[NSNumber alloc] autorelease] initWithInt:1]];
推荐答案
Yes, just use one of the many helper functions such as numberWithInt:
:
[Tyler setArms:[NSNumber numberWithInt:1]];
表达式[NSNumber numberWithInt:1]
等效于[[[NSNumber alloc] initWithInt:1] autorelease]
,等效于[[[NSNumber alloc] autorelease] initWithInt: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.
这篇关于NSNumber文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!