nsinteger

How to convert An NSInteger to an int?

混江龙づ霸主 提交于 2019-11-27 06:51:19
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. Dave DeLong Ta da: NSInteger myInteger = 42; int myInt = (int) myInteger; NSInteger is nothing more than a 32/64 bit int. (it will use the appropriate size based on what OS/platform you're running) If you want to do this inline, just cast the NSUInteger or NSInteger to an int : int i = -1; NSUInteger row = 100; i > row // true, since the signed int is implicitly converted to an unsigned int i

What's the difference between NSNumber and NSInteger?

拟墨画扇 提交于 2019-11-27 04:10:28
问题 What's the difference between NSNumber and NSInteger? Are there more primitives like these that I should know about? Is there one for floats? 回答1: The existing answers are useful; adding to them: Yes, NSUInteger gives twice the range among positive integers as NSInteger , but I think another critical reason to choose between the two is simply to distinguish among cases where negative values simply do not make sense . Example: the return value of NSArray 's count method is an NSUInteger ,

Why don't I declare NSInteger with a *

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 00:51:12
问题 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 *processID = [[NSProcessInfo processInfo] processIdentifier]; Which generated an error, after tinkeing around blindly, I discovered that it was the * in the NSInteger line that was causing the problem. So I obviously don't understand what's happening. I'll

How to convert An NSInteger to an int?

↘锁芯ラ 提交于 2019-11-26 12:09:49
问题 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. 回答1: Ta da: NSInteger myInteger = 42; int myInt = (int) myInteger; NSInteger is nothing more than a 32/64 bit int. (it will use the appropriate size based on what OS/platform you're running) 回答2: If you want to do this inline, just cast the NSUInteger or NSInteger to an int : int i = -1;

When to use NSInteger vs. int

孤者浪人 提交于 2019-11-26 01:34:45
问题 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;... - (void)someFuncWithInt:(NSInteger)value;... But within a function they\'re just using int to track a value for (int i; i < something; i++) ... int something; something += somethingElseThatsAnInt; ... I\'ve read (been told) that NSInteger is a safe