1

I am using the Spotify iOS SDK and I am storing a session using NSKeyedUnarchiver

However the following code causes an error(some code omitted just for clarity's sake):

sptSession = NSKeyedUnarchiver.unarchiveObjectWithData(sessionData as! NSData)
let auth = SPTAuth.defaultInstance()
auth.session = sptSession as! SPTSession

The last line of code is throwing the error Could not cast value of type 'SPTSession' (0x110afab98) to 'SPTSession' (0x10f17f638). I read that error as somehow there are two different types of SPTSessions but I'm not sure why or how to resolve the issue.

Alex Harris
  • 6,172
  • 2
  • 32
  • 57

1 Answers1

1

the answer seems to be related to this SO post:

Swift only way to prevent NSKeyedUnarchiver.decodeObject crash?

I have added an issue to the GH repo for Spotify's iOS SDK (https://github.com/spotify/ios-sdk/issues/759), and posted this temporary workaround as a comment on the issue:

for the time being, I have found a workaround - I can simply write NSKeyedArchiver.setClassName("SPTSession", for: SPTSession.self) before I archive the session, and write NSKeyedUnarchiver.setClass(SPTSession.self, forClassName: "SPTSession") before unarchiving.

While this fixes the crash, I will leave the issue open as I am not sure if a change can be made in the underlying library to fix this

Community
  • 1
  • 1