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

1

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.