6

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

@4
jscs
  • 63,694
  • 13
  • 151
  • 195
  • It makes it an ```NSNumber```. – gtmtg Jul 13 '13 at 11:48
  • 2
    See "NSNumber Literals" in http://clang.llvm.org/docs/ObjectiveCLiterals.html. – Martin R Jul 13 '13 at 11:49
  • 1
    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. – Hot Licks Jul 13 '13 at 12:43

1 Answers1

7

It is the NSNumber literal. A shortcut for this:

[NSNumber numberWithInt:4];
DrummerB
  • 39,814
  • 12
  • 105
  • 142
  • Do you know its equivalent in swift 2.3 and swift 3.0? – Ravi Sharma Apr 14 '17 at 05:52
  • 1
    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)` – DrummerB Apr 14 '17 at 12:37