NSNumber文字 [英] NSNumber Literals

查看:61
本文介绍了NSNumber文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆