NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

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> = [
    ].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 Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until October 1st.

Click to save your free spot now

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.