nsinteger

Convert NSInteger to NSIndexpath

China☆狼群 提交于 2019-12-17 22:44:10
问题 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. 回答1: 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]; 回答2: If you

How do I convert NSInteger to NSString datatype?

五迷三道 提交于 2019-12-17 17:24:39
问题 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]]; 回答1: 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]; 回答2: Obj-C way =): NSString *inStr = [@(month) stringValue]; 回答3: Modern Objective-C An NSInteger has the method stringValue

Convert NSString to NSInteger?

随声附和 提交于 2019-12-17 07:14:05
问题 I want to convert string data to NSInteger . 回答1: If the string is a human readable representation of a number, you can do this: NSInteger myInt = [myString intValue]; 回答2: [myString intValue] returns a cType "int" [myString integerValue] returns a NSInteger . In most cases I do find these simple functions by looking at apples class references, quickest way to get there is click [option] button and double-click on the class declarations (in this case NSString ). 回答3: I've found this to be the

Convert NSString to NSInteger?

Deadly 提交于 2019-12-17 07:14:03
问题 I want to convert string data to NSInteger . 回答1: If the string is a human readable representation of a number, you can do this: NSInteger myInt = [myString intValue]; 回答2: [myString intValue] returns a cType "int" [myString integerValue] returns a NSInteger . In most cases I do find these simple functions by looking at apples class references, quickest way to get there is click [option] button and double-click on the class declarations (in this case NSString ). 回答3: I've found this to be the

What is the difference between primitive data type vs an non primitive data type(apple defined data type)? [closed]

最后都变了- 提交于 2019-12-13 11:24:55
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . What's the basic difference between the two..? it would be nice if can someone explain using the example of NSInteger and NSNumber.. Thanks 回答1: The main difference is related to where they stay in the memory,

Why am I getting strange values in my NSInteger object?

若如初见. 提交于 2019-12-12 04:21:18
问题 I am parsing XML that gets returned from a web service. If it is a valid user than I should be getting a long integer back. (for example: 2110504192344912815 or 2061128143657912001). If it is invalid then I get a 0. However if you see my code, I am getting negative values sometimes for userID and that is throwing my validation code hay wire. Any tips? NSMutableString *loginString; NSInteger userID; -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *) elementName namespaceURI:

Assemble date object from integers?

孤者浪人 提交于 2019-12-11 06:18:44
问题 Given three integers, representing a day, month and year, what code would assemble those integers into a date object? 回答1: You should look at NSDateComponents : int y = 2011; int m = 1; int d = 15; NSDateComponents *dc = [[NSDateComponents alloc] init]; [dc setYear:y]; [dc setMonth:m]; [dc setDay:d]; NSLog(@"%@: %@", [[dc date] class], [dc date]); 回答2: NSDateFormatter uses the Unicode Standard for parsing date strings into dates. So, format your integers into a date string and then use and

Is there a better way to avoid 'Sign comparison' warning when comparing NSIndexPath's row and NSArray count?

拟墨画扇 提交于 2019-12-10 13:13:05
问题 I turned 'Signed Comparision' (aka -Wsign-compare) warnings for my iOS project in XCode (surprisingly, it was off by default). After that lots of warnings like this appeared: /Users/michalciuba/projects/GlobeMobile/Classes/ACMailController.m:86:19: Comparison of integers of different signs: 'NSInteger' (aka 'long') and 'NSUInteger' (aka 'unsigned long') They are usually caused by comparing row property of NSIndexPath which is NSInteger to the value returned by 'count' method of NSArray , like

Int or NSInteger as object for method argument. Objective-C

本小妞迷上赌 提交于 2019-12-09 09:05:17
问题 I'm having some trouble passing a number as an argument for a method: - (void)meth2:(int)next_int; And to call that method I need this: int next_int = 1; [self performSelectorOnMainThread:@selector(meth2:) withObject:next_int waitUntilDone:NO]; //update next_int and call meth2 again at this point, I get a "pointer from integer without a cast" error and would happen the same with a NSInteger . An NSNumber is not useful because it's immutable and I need to change the value constantly. Any idea

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

杀马特。学长 韩版系。学妹 提交于 2019-12-09 07:41:34
问题 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! 回答1: NSInteger sum = 0; for (NSNumber *num in myArray) { sum += [num intValue]; } 回答2: You can use this: NSArray* numbers = //array of numbers NSNumber* sum = [numbers valueForKeyPath: @"@sum.self"]; 回答3: long long sum = ((NSNumber*)[array valueForKeyPath: @"@sum.longLongValue"]).longLongValue;