如何提取 64 位有符号整数值 [英] how to extract 64 bit signed integer value
问题描述
我正在查询 NSDictionary 的值.因为我遇到了问题,所以我打印了对象.它向我展示了以下内容:
所以它是有符号的 64 位整数类型.所以我试图提取这样的值 这给了我一个值,但该值不是字典中的值. 我也试过这个 但我收到警告 我想要的价值是例如1286301600.一个有符号整数(-2.147.483.648 到 2.147.483.647)应该做我想做的事情.我不明白为什么 Cocoa 试图制作一个 64 位有符号整数. 如何提取字典的 64 位有符号整数并将其用作变量? 返回对象(我想 - NSNumber),而不是标量数.如果它确实是一个 NSNUMer 对象,那么您可以使用以下函数之一从中获取一个数字: 以下行必须根据您的号码生成正确的字符串: I'm querying a NSDictionary for a value. Because I got problems I printed the object. It shows me the following: So it is of type signed 64 bit integer. So I tried to extract the value like this That gives me a value but the value is not the one in the dictionary. I also tried this but I get the warning The value I would like to have is e.g. 1286301600. A signed integer (−2.147.483.648 to 2.147.483.647) should do the thing I want. I don't understand why Cocoa is trying to make a 64 bit signed Integer. How can I extract the 64 bit signed integer of the dictionary and use it as a variable? Returns object (I suppose - NSNumber), not a scalar number. If it is really a NSNUmber object then you can get a number from it using one of the following functions: The following line must produce correct string from your number:
这篇关于如何提取 64 位有符号整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!NSString *myString = [NSString stringWithFormat:@"%qi", [myDictionary objectForKey:@"myDictionaryItem"]];
long long my64bitsignedIntegerValue = (long long)[myDictionary objectForKey:@"myDictionaryItem"];
Cast from pointer to integer of different size
.这不起作用,因为 stringWithFormat
正在返回 id
类型的值.我发现这个 post 其中 id
是 UInt32
类型.并且有符号的 64 位整数不是无符号的 32 位整数,所以我收到了这个警告.如果我忽略警告,值仍然是错误的.[myDictionary objectForKey:@"myDictionaryItem"]
-intValue-longValue-longLongValue
NSString *myString = [NSString stringWithFormat:@"%qi", [[myDictionary objectForKey:@"myDictionaryItem"] intValue]];
<CFString 0x5d33630 [0x26af380]>{contents = "myDictionaryItem"} = <CFNumber 0x5d58940 [0x26af380]>{value = +1286301600, type = kCFNumberSInt64Type}
NSString *myString = [NSString stringWithFormat:@"%qi", [myDictionary objectForKey:@"myDictionaryItem"]];
long long my64bitsignedIntegerValue = (long long)[myDictionary objectForKey:@"myDictionaryItem"];
Cast from pointer to integer of different size
. That doesn't work because stringWithFormat
is returning a value of type id
. I found this post where id
is of type UInt32
. And a signed 64 bit integer is not unsigned 32 bit integer, so I get this warning. If I ignore the warning, the value is still wrong.[myDictionary objectForKey:@"myDictionaryItem"]
-intValue
-longValue
-longLongValue
NSString *myString = [NSString stringWithFormat:@"%qi", [[myDictionary objectForKey:@"myDictionaryItem"] intValue]];