BLACK FRIDAY SALE: Save 50% on all my Swift books and bundles! >>

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?

1      

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 }

1      

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.

1      

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

1      

Hacking with Swift is sponsored by Guardsquare

SPONSORED AppSweep by Guardsquare helps developers automate the mobile app security testing process with fast, free scans. By using AppSweep’s actionable recommendations, developers can improve the security posture of their apps in accordance with security standards like OWASP.

Learn more

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.