1

Is there is no needs of declaring NSInteger using the alloc and initialise keyword? and why?

I was trying doing NSInteger *choice = [[NSInteger alloc] init]; while I found direct assignment

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Sam
  • 571
  • 1
  • 6
  • 22
  • possible duplicate of [When to use NSInteger vs int?](http://stackoverflow.com/questions/4445173/when-to-use-nsinteger-vs-int) – Black Frog Feb 16 '14 at 09:39

2 Answers2

3

NSInteger is just typedef of int or long (depends on platform)

So you can initialize something like that

NSInteger i = 10;

Quote from SDK documentation

NSInteger Used to describe an integer.

typedef long NSInteger;

When building 32-bit applications, NSInteger is a 32-bit integer. A 64-bit application treats NSInteger as a 64-bit integer.

https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html

Sergey Pekar
  • 8,555
  • 7
  • 47
  • 54
1

NSInteger is not an Objective-C object. It's a datatype (much like C's int or char types). You do not need to call "alloc" (to explicitly allocate memory space) for it.

You can read up on the other Objective-C data types (like NSRange, which you'll use a lot of once you get into NSString objects) in this Apple documentation.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215