Reputation: 139
I have a library from zendesk for iOS and I use a number they give me to sort help desk items by category. This is how I tell it what category I want:
hcConfig.groupIds = [115000159351]
However, XCODE is throwing the error of
Integer literal '115000159351' overflows when stored into 'Int'
Ok, I understand. Probably because the number is more than 32 bits. But I have another app I made that I have an equally long number with, and that one builds just fine with no errors. Same exact code, except slightly different number.
hcConfig.groupIds = [115000158052]
Why will one project build but the other will not?
For reference here is their instructions: https://developer.zendesk.com/embeddables/docs/ios_support_sdk/help_center#filter-articles-by-category
Upvotes: 2
Views: 1403
Reputation: 3666
When both the integers converted to binary they needed equal bits around ~37
1101011000110100010110010110001110111 = 115000159351
1101011000110100010110010011101100100 = 115000158052
So, it seems that the one which is working is compiled as 64 bit app, where in the one failing is being compiled as 32 bit app. Please verify once.
Please refer How to convert xcode 32 bit app into 64 bit xcode app to convert your app from 32 bit to 64 bit
For using large numbers in NSNumber use following method :
NSNumber *value = [NSNumber numberWithLongLong:115000159351];
Further, following code works fine for me on 32 bit also :
var groupIds = [NSNumber]();
groupIds = [115000158052, 115000158053, 115000158054]
groupIds = [115000158052 as NSNumber, 115000158053 as NSNumber, 115000158054 as NSNumber]
groupIds = [115000158052 as Int64 as NSNumber, 115000158053 as Int64 as NSNumber, 115000158054 as Int64 as NSNumber]
I think groupIds are not NSNumber but Int.
Upvotes: 2
Reputation: 539815
The Swift Int
is a 32-bit or 64-bit integer, depending on the platform.
To create a NSNumber
(array) from a 64-bit literal on all platforms, use
let groupIds = [NSNumber(value: 115000159351 as Int64)]
or
let groupIds = [115000159351 as Int64 as NSNumber]
Upvotes: 3