FREE TRIAL: Accelerate your app development career with Hacking with Swift+! >>

Integer literal overflows when stored into NSNumber

Forums > macOS

So I'm messing around with iTunesLibrary and I am loading test data into a structure. One of the structure properties is an array of track persistentID's. So, I setup the array as such:

var tracks:Array<NSNumber> = [8531377916780748525,10894448951054098798,1913808070485867300,3944816338394235389,930561036379062783,3251308436698647533,14952971713326701209,14970963935055520988,14311328294714471790,8057477945548486586]

Playground does the same thing.

These numbers came from the iTunesLibrary persistentID's for specific tracks, so why don't they work? All I'm doing is manually adding a few track persistentID's to an array for testing purposes. How can an NSNumber not fit within an NSNumber?

   

I'm not 100% certain this is the answer, but see my post in your previous thread... Dictionary and NSNumber overflow errors

And here's what I did to make your code work:

var tracks:Array<NSNumber> = [
    8531377916780748525,
    10894448951054098798,
    1913808070485867300,
    3944816338394235389,
    930561036379062783,
    3251308436698647533,
    14952971713326701209,
    14970963935055520988,
    14311328294714471790,
    8057477945548486586
    ].map { $0 as UInt64 as NSNumber }

   

Yeah, I has seen a post where they recommended using UInt64 because there are issues with NSNumber. I guess I'll just refactor what I've written. It's not like I'll be writing to the iTunesLibrary.

   

Oh wait. I now see what you did there. I'll give that a try before refactoring!

   

Hacking with Swift is sponsored by Sentry

SPONSORED With Sentry’s error and performance monitoring for iOS you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.

Get started

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.