What does it mean when you put an @ before an integer in Objective-C?
Asked Answered
R

1

6

What does it mean when you put an @ before an integer in Objective-C? Like so:

@4
Rattlepate answered 13/7, 2013 at 11:45 Comment(4)
It makes it an NSNumber.Grievance
See "NSNumber Literals" in clang.llvm.org/docs/ObjectiveCLiterals.html.Monophyletic
Note that this is a relatively new compiler feature, so many books and other references will not discuss it. It goes with the notation of @[a,b,c] for an NSArray and several other enhancements, as shown in Martin R's link.Thunder
Does this answer your question? What does the @ symbol represent in objective-c?Welltodo
T
7

It is the NSNumber literal. A shortcut for this:

[NSNumber numberWithInt:4];
Tiein answered 13/7, 2013 at 11:47 Comment(2)
Do you know its equivalent in swift 2.3 and swift 3.0?Clawson
You should probably use the Swift numeric types instead, like Int, Float etc. If you really need to use NSNumber in Swift, you can do it like this: var num = NSNumber(value: 4)Tiein

© 2022 - 2024 — McMap. All rights reserved.