Questions tagged [nsinteger]

An NSInteger is a data type in Objective-C. It is used to describe an integer.

An NSInteger is data type in Objective-C used to describe an integer. When building 32-bit applications, NSInteger is a 32-bit integer. A 64-bit application treats NSInteger as a 64-bit integer.

260 questions
345
votes
8 answers

When to use NSInteger vs. int

When should I be using NSInteger vs. int when developing for iOS? I see in the Apple sample code they use NSInteger (or NSUInteger) when passing a value as an argument to a function or returning a value from a function. - (NSInteger)someFunc;... -…
Shizam
  • 9,507
  • 8
  • 47
  • 81
144
votes
5 answers

Why does an NSInteger variable have to be cast to long when used as a format argument?

NSInteger myInt = 1804809223; NSLog(@"%i", myInt); <==== The code above produces an error: Values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead The corrected NSLog message is actually…
Daniel Lee
  • 1,471
  • 2
  • 10
  • 5
140
votes
9 answers

How do I convert NSInteger to NSString datatype?

How does one convert NSInteger to the NSString datatype? I tried the following, where month is an NSInteger: NSString *inStr = [NSString stringWithFormat:@"%d", [month intValue]];
senthilMuthu
  • 9,258
  • 18
  • 74
  • 139
134
votes
3 answers

NSLog/printf specifier for NSInteger?

A NSInteger is 32 bits on 32-bit platforms, and 64 bits on 64-bit platforms. Is there a NSLog specifier that always matches the size of NSInteger? Setup Xcode 3.2.5 llvm 1.6 compiler (this is important; gcc doesn't do…
Steven Fisher
  • 43,056
  • 20
  • 131
  • 184
98
votes
4 answers

How to convert An NSInteger to an int?

For example when passing a value message to an NSInteger instance like so [a value] it causes an EXC_BAD_ACCESS. So how to convert an NSInteger to int? If it's relevant only small numbers < 32 are used.
Jeffrey
  • 1,342
  • 3
  • 11
  • 18
75
votes
7 answers

Convert NSString to NSInteger?

I want to convert string data to NSInteger.
The deals dealer
  • 966
  • 2
  • 7
  • 15
61
votes
5 answers

What's the difference between NSNumber and NSInteger?

What's the difference between NSNumber and NSInteger? Are there more primitives like these that I should know about? Is there one for floats?
mk12
  • 24,644
  • 29
  • 92
  • 132
54
votes
3 answers

Alternatives to type casting when formatting NS(U)Integer on 32 and 64 bit architectures?

With the 64 bit version of iOS we can't use %d and %u anymore to format NSInteger and NSUInteger. Because for 64 bit those are typedef'd to long and unsigned long instead of int and unsigned int. So Xcode will throw warnings if you try to format…
Matthias Bauch
  • 88,097
  • 19
  • 217
  • 244
42
votes
3 answers

Is it possible to cast an NSInteger to NSNumber?

Is it possible to cast a NSInteger to a NSNumber object? I need to convert the tag of a UIImageView object to a NSNumber object because I need to pass it as an argument to a function.
Fitzy
  • 1,803
  • 6
  • 23
  • 38
42
votes
5 answers

Why don't I declare NSInteger with a *

I'm trying my hand at the iPhone course from Stanford on iTunes U and I'm a bit confused about pointers. In the first assignment, I tried doing something like this NSString *processName = [[NSProcessInfo processInfo] processName]; NSInteger…
gargantuan
  • 8,670
  • 14
  • 63
  • 105
39
votes
4 answers

enum values: NSInteger or int?

tl;dr Version How are the data types of an enum's constants guaranteed to be NSUInteger instead of unsigned int when declaring an enum thusly: enum { NSNullCellType = 0, NSTextCellType = 1, NSImageCellType = 2 }; typedef NSUInteger…
Michael Fey
  • 1,249
  • 1
  • 9
  • 15
38
votes
4 answers

Convert NSInteger to NSIndexpath

Basically I am storing an index of an array in a NSInteger. I now need it as an NSIndexpath, I'm struggling to see and find a way to convert my NSInteger to NSIndexpath so I can reuse it.
Dan
  • 1,437
  • 2
  • 13
  • 30
36
votes
2 answers

Difference between int, NSInteger and NSUInteger

What is the main difference between int, NSInteger and NSUInteger in Objective-C? Which one is better to use in an application and why?
Hitarth
  • 1,836
  • 3
  • 26
  • 49
35
votes
4 answers

What is the maximum value of NSInteger?

I need to store the maximum value of an NSInteger into an NSInteger? What is the correct syntax to do it? Thanks.
David
  • 13,850
  • 20
  • 90
  • 143
26
votes
6 answers

How get the total sum of NSNumber's from a NSArray?

I have a large NSArray containing NSNumbers like 3, 4, 20, 10, 1, 100, etc... How do I get the total sum of all these NSNumbers (3 + 4 + 20 + 10 + 1 + 100 + etc...) as one total NSInteger? Thank you!
neowinston
  • 6,762
  • 9
  • 49
  • 80
1
2 3
17 18