nsinteger

iOS : NSInteger and NSUInteger comparison

对着背影说爱祢 提交于 2021-02-18 08:39:53
问题 Surprise! I've a variable like this, NSInteger index = 0; I'm comparing it with one of subviews count (which returns NSUInteger ) like this, if((index-1) <= [[currentmonth subviews] count]) { NSLog(@"true"); } else { NSLog(@"false"); } This always giving false. but If I'll do like this, if ((index-1) <= 42) { NSLog(@"true"); } else { NSLog(@"false"); } This always giving true. I feel that, this because we can't compare NSInteger with NSUInteger correct? I caught this issue, when I have a

Store NSInteger in Core Data

不羁的心 提交于 2020-01-06 05:39:25
问题 Is there any way I can skip dealing with NSNumber and work directly with NSInteger? 回答1: Core Data will only allow NSNumbers. However, you can write custom getters and setters to use NSInteger properties. mogenerator is a wonderful tool that does that automatically for you: it generates classes with native properties for all your entities. 回答2: No. NSInteger is just a typedef for a long integer, not an object. Actual implementation: #if __LP64__ || NS_BUILD_32_LIKE_64 typedef long NSInteger;

NSInteger versus int [duplicate]

自闭症网瘾萝莉.ら 提交于 2020-01-03 20:31:29
问题 This question already has answers here : When to use NSInteger vs. int (8 answers) Closed 5 years ago . What would be the reason to use an NSInteger vs an int in iPhone programming? Thanks. 回答1: An NSInteger is just a typedef with the following definition: #if __LP64__ || NS_BUILD_32_LIKE_64 typedef long NSInteger; typedef unsigned long NSUInteger; #else typedef int NSInteger; typedef unsigned int NSUInteger; #endif As the typedef is defined differently basing on the platform, you can keep

NSInteger versus int [duplicate]

独自空忆成欢 提交于 2020-01-03 20:31:09
问题 This question already has answers here : When to use NSInteger vs. int (8 answers) Closed 5 years ago . What would be the reason to use an NSInteger vs an int in iPhone programming? Thanks. 回答1: An NSInteger is just a typedef with the following definition: #if __LP64__ || NS_BUILD_32_LIKE_64 typedef long NSInteger; typedef unsigned long NSUInteger; #else typedef int NSInteger; typedef unsigned int NSUInteger; #endif As the typedef is defined differently basing on the platform, you can keep

Convert NSInteger to NSUInteger?

空扰寡人 提交于 2019-12-31 12:06:22
问题 I am trying to convert a NSInteger to a NSUInteger and I googled it and found no real answer. How would I do this? 回答1: NSInteger and NSUInteger are just typedefs for primitive integer types: #if __LP64__ || NS_BUILD_32_LIKE_64 typedef long NSInteger; typedef unsigned long NSUInteger; #else typedef int NSInteger; typedef unsigned int NSUInteger; #endif As such, you don't need to "convert" between them. A simple cast should be sufficient. Like: NSInteger myInt = 0; NSUInteger unsignedInt =

retrieving integer value from the UITextField into a NSInteger variable

≡放荡痞女 提交于 2019-12-29 09:07:39
问题 UITextField *textField; NSInteger intRollNumber; I want to take rollNumber as input from the textField and store the value into intRollNumber . How i do that? Because I am unable to convert the string into integer. 回答1: Like this? NSString *str = [textField text] int RollNumber = [str intValue]; 回答2: See the text property and integerValue. 来源: https://stackoverflow.com/questions/886925/retrieving-integer-value-from-the-uitextfield-into-a-nsinteger-variable

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

旧街凉风 提交于 2019-12-29 02:33:13
问题 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

Why does this conditional cause an error?

社会主义新天地 提交于 2019-12-24 18:50:31
问题 I have a method that contains a few conditionals. The first conditional works fine and does not cause any problems. However, the second one causes the app to crash. - (void)didReceiveGaiaGattResponse:(CSRGaiaGattCommand *)command { GaiaCommandType cmdType = [command getCommandId]; NSData *requestPayload = [command getPayload]; uint8_t success = 0; NSLog(@"cmdType: %li", (long)cmdType); [requestPayload getBytes:&success range:NSMakeRange(0, sizeof(uint8_t))]; if (cmdType == GaiaCommand

What is the difference between int and NSInteger? [duplicate]

落花浮王杯 提交于 2019-12-20 18:03:46
问题 This question already has answers here : Closed 8 years ago . Possible Duplicates: When to use NSInteger vs int? Why is there is an NSInteger? Can we use int and NSInteger interchangably? Is there any specific situation to use NSInteger only, instead of using int ? 回答1: Can we use int and NSInteger interchangably? No. On the LP64 architecture used by Apple, for modern OS X Cocoa, NSInteger is 64 bits wide. This means that if you cast an NSInteger to an int, comparisons against NSNotFound may

NSUInteger in reversed loop confusion?

社会主义新天地 提交于 2019-12-20 06:26:52
问题 I wonder if someone can explain something, I setup a loop where I wanted to count backwards from 10 to 0 : for(NSUInteger index = 10; index >= 0; index--) { NSLog(@"INDEX: %ld", (long)index); } This loop runs forever, it does not stop at 0, but keeps going into negative numbers. When I noticed this I changed my code to : for(NSInteger index = 10; index >= 0; index--) { NSLog(@"INDEX: %ld", (long)index); } The above works fine, but I am curious, why the first example does not work as the