nsinteger

Convert NSInteger to NSIndexpath

不想你离开。 提交于 2019-11-28 20:06:24
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. For an int index : NSIndexPath *path = [NSIndexPath indexPathWithIndex:index]; Creates Index of the item in node 0 to point to as per the reference . To use the indexPath in a UITableView , the more appropriate method is NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:section]; If you need a NSIndexPath for a UITableView , you can use indexPathForRow:inSection: ( reference ). Index paths passed

enum values: NSInteger or int?

北慕城南 提交于 2019-11-28 17:27:09
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 NSCellType; The typedef to NSUInteger does not appear to be tied to the enum declaration in any way. Full Version I was reading through Apple's 64-Bit Transition Guide for Cocoa for some guidance on enum values and I came away with a question. Here's a (lengthy) quote from the Enumeration Constants section, emphasis mine: A problem with enumeration (enum) constants

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

我只是一个虾纸丫 提交于 2019-11-28 15:38:58
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 NSInteger with %d. Xcode is nice to us and offers an replacement for those two cases, which consists of a l-prefixed format specifier and a typecast to long. Then our code basically looks like this: NSLog(@"%ld", (long)i); NSLog(@"%lu", (unsigned long)u); Which, if you ask me, is a pain in the eye. A couple of days ago someone at Twitter mentioned

NSLog/printf specifier for NSInteger?

心不动则不痛 提交于 2019-11-28 14:42:56
问题 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 this) GCC_WARN_TYPECHECK_CALLS_TO_PRINTF turned on That's causing me some grief here: #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { @autoreleasepool { NSInteger i = 0; NSLog(@"%d", i); } return 0; } For 32 bit code, I need the %d specifier. But if

What is the maximum value of NSInteger?

喜欢而已 提交于 2019-11-28 07:12:52
I need to store the maximum value of an NSInteger into an NSInteger? What is the correct syntax to do it? Thanks. Chuck The maximum value of an NSInteger is NSIntegerMax . The maximum value for an NSInteger is NSIntegerMax (from Foundation Constants Reference ) Took me a little while for me to realise why I was getting a different value from NSIntegerMax when using NSUInteger!! And the maximum for a NSUInteger is NSUIntegerMax (also from http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Miscellaneous/Foundation_Constants/Reference/reference.html ) For 32-bit & 64

Why don't I declare NSInteger with a *

こ雲淡風輕ζ 提交于 2019-11-28 05:14:43
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 explain how I think it works and perhaps someone would be kind enough to point out the flaw. Unlike in

How do I convert NSInteger to NSString datatype?

房东的猫 提交于 2019-11-28 02:54:30
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]]; NSIntegers are not objects, you cast them to long , in order to match the current 64-bit architectures' definition: NSString *inStr = [NSString stringWithFormat: @"%ld", (long)month]; Obj-C way =): NSString *inStr = [@(month) stringValue]; MadNik Modern Objective-C An NSInteger has the method stringValue that can be used even with a literal NSString *integerAsString1 = [@12 stringValue]; NSInteger number = 13;

enum values: NSInteger or int?

爷,独闯天下 提交于 2019-11-27 20:08:28
问题 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 NSCellType; The typedef to NSUInteger does not appear to be tied to the enum declaration in any way. Full Version I was reading through Apple's 64-Bit Transition Guide for Cocoa for some guidance on enum values and I came away with a question. Here's a (lengthy)

What's the difference between NSNumber and NSInteger?

Deadly 提交于 2019-11-27 16:59:35
What's the difference between NSNumber and NSInteger? Are there more primitives like these that I should know about? Is there one for floats? Tyler 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 , which makes sense since we cannot have an array with a negative number of elements. When the coder knows

How to evaluate the string equation in ios

喜夏-厌秋 提交于 2019-11-27 15:51:09
问题 Is there way to solve the string equations in ios ? For example Input: NSString * str =@"1+2"; Output: NSInteger result = 3 // i.e sum of 1+2 from str How to go about this and get expected result! Please help! 回答1: You can use NSExpression for this: NSExpression *expression = [NSExpression expressionWithFormat:@"1+2"]; NSLog(@"%@", [expression expressionValueWithObject:nil context:nil]); For further information read the documentation of the used methods. 回答2: If your mathematical expressions