新目标文字在4.4 [英] New Objective-c Literals in 4.4
问题描述
我可以写 @ 42
,它创建一个 NSNumber
和 int
value 42.我可以使用一个变量,如 @someIntVar
吗?显然,我尝试它,它不工作(这吸吮,因为然后我必须通过 [NSNumber numberWithInt:someIntVar]
)。是否可能使用稍微不同的语法?
I can write @42
, which creates an NSNumber
with int
value 42. Can I do this with a variable, like @someIntVar
? Obviously I tried it and it doesn't work (which sucks because then I have to go through [NSNumber numberWithInt:someIntVar]
). Is it possible with a slightly different syntax?
推荐答案
我强烈建议您阅读官方clang文档: http://clang.llvm.org/docs/ObjectiveCLiterals.html
I strongly suggest you read the official clang documentation on the matter: http://clang.llvm.org/docs/ObjectiveCLiterals.html
但是,对于一个变量或任何表达式,你可以使用括号:
But, to box a variable, or any expression, you can use parentheses:
id num = @(someIntVar);
这篇关于新目标文字在4.4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!