New Objective-c Literals in 4.4

一个人想着一个人 提交于 2019-12-10 09:26:46

问题


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?


回答1:


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);


来源:https://stackoverflow.com/questions/12120153/new-objective-c-literals-in-4-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!