我对Objective-C很陌生。我知道 C 和 C++,但 Objective-C 有相当多的学习曲线。无论如何,是否有更短的方法(如果存在的话,可能通过某种 NSNumber 文字)来编写以下内容:
[Tyler setArms:[[[NSNumber alloc] autorelease] initWithInt:1]];
最佳答案
是的,只需使用许多辅助函数之一,例如 numberWithInt:
:
[Tyler setArms:[NSNumber numberWithInt:1]];
表达式
[NSNumber numberWithInt:1]
等价于 [[[NSNumber alloc] initWithInt:1] autorelease]
,后者等价于 [[[NSNumber alloc] autorelease] initWithInt:1]
。后一种表达极为罕见。关于objective-c - NSNumber 字面量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5373746/