NEW: Learn SwiftData for free with my all-new book! >>

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 Judo

SPONSORED Let’s face it, SwiftUI previews are limited, slow, and painful. Judo takes a different approach to building visually—think Interface Builder for SwiftUI. Build your interface in a completely visual canvas, then drag and drop into your Xcode project and wire up button clicks to custom code. Download the Mac App and start your free trial today!

Try 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.