Closed aaizuss closed 8 years ago
@aaizuss Based on the error message you're getting, it looks like you're using decodeInt64ForKey:
, which returns an Int64
, a different type from a plain Int
. You should be using decodeIntegerForKey
. Let us know if that solves the problem!
I also have office hours today from 4-6pm if you want me to take a look at your code with you.
I've been using decodeIntegerForKey, so there's nothing to fix there. I'll go to office hours.
@susanstevens I don't know if this is relevant, but I added a few print statements: immediately inside encodeWithCoder (first line of the function), after calling encodeInteger, and immediately before and after calling decodeIntegerForKey.
The app crashes after printing "about to decode an integer". Strangely, it never prints any of the statements in the encodeWithCoder method.
@aaizuss Is saveMeals()
being called?
@susanstevens yes - and i just read through the Persist Data section again and checked to make sure I followed everything exactly
@aaizuss Hmmm... I'll have to look at the code to see what's going on. It's definitely strange that encodeWithCoder:
isn't being called.
I am having the same issue. Was there a resolution?
@nickpann I just had to reset content and settings in simulator.
I just completed the tutorial, and I ran my app to test that the data persists, and it worked initially - I added 2 meals, went to the home screen, returned to the app, and the 2 meals were there. But when I stopped the simulator and ran it again, the app crashed. Xcode highlights the AppDelegate class, shows "Thread 1: signal SIGABRT" and the debug window says "libc++abi.dylib: terminating with uncaught exception of type NSException".
At the top of the log, it says * Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '* -[NSKeyedUnarchiver decodeInt64ForKey:]: value for key (rating) is not an integer number'. But I checked Meal.swift and rating appears to be an Int. In required convenience init?, when I try to force cast rating as an int, I get a warning that "forced cast of Int to same type has no effect."
I've also double checked that I all of my code matches what the "Persist Data" section of the tutorial says.