Chap 2: Error When Cancelling "Rate"

In both the FINAL project, as well as my project after following the book (with updates on page 45-ish), I put the program through its paces, and have a certain situation that I cannot recover from without restarting.

When rating a bowtie, entering an invalid value, the Alert dialog pops back up, as designed… I then decide to cancel the rating (hit cancel). At that point, regardless which bowtie I select, I can no longer update any “Wear” or “Rate” values.

Are there any suggestions how to deal with a “Cancel” action? And/or, this brings up the need to learn how to troubleshoot what is happening in “my” code that probably traces back to Core Data library code… Or is there something simple that I am missing?

It should be noted, if the user cancels a “Rate” action before entering an invalid value, the program operates as expected. Troubleshooting a second UIAlertController, with a “cancel” action has been a challenge.

THANKS!

This is the output from the console. Note: whichever bowtie was selected when the Rating action was cancelled will be referenced in this output:

Could not fetch Error Domain=NSCocoaErrorDomain Code=1620 “The operation couldn’t be completed. (Cocoa error 1620.)” UserInfo={NSValidationErrorObject=<Bow_Ties.Bowtie: 0x6180000c3cd0> (entity: Bowtie; id: 0xd000000000180000 x-coredata://0C7CB81E-8B86-428A-AEB4-B84007BCE203/Bowtie/p6 ; data: {
isFavorite = 0;
lastWorn = “2014-06-16 18:15:24 +0000”;
name = “Orange Bow Tie”;
photoData = <89504e47 0d0a1a0a 0000000d 49484452 000003e8 000003e8 08020000 00c2c143 b3000000 01735247 4200aece 1ce90000 001c>;
rating = “-1”;
searchKey = O;
timesWorn = 2;
tintColor = “UIExtendedSRGBColorSpace 1 0.627451 0.478431 1”;
}), NSValidationErrorValue=-1, NSValidationErrorKey=rating, NSLocalizedDescription=The operation couldn’t be completed. (Cocoa error 1620.)}, [AnyHashable(“NSLocalizedDescription”): The operation couldn’t be completed. (Cocoa error 1620.), AnyHashable(“NSValidationErrorValue”): -1, AnyHashable(“NSValidationErrorObject”): <Bow_Ties.Bowtie: 0x6180000c3cd0> (entity: Bowtie; id: 0xd000000000180000 x-coredata://0C7CB81E-8B86-428A-AEB4-B84007BCE203/Bowtie/p6 ; data: {
isFavorite = 0;
lastWorn = “2014-06-16 18:15:24 +0000”;
name = “Orange Bow Tie”;
photoData = <89504e47 0d0a1a0a 0000000d 49484452 000003e8 000003e8 08020000 00c2c143 b3000000 01735247 4200aece 1ce90000 001c>;
rating = “-1”;
searchKey = O;
timesWorn = 2;
tintColor = “UIExtendedSRGBColorSpace 1 0.627451 0.478431 1”;
}), AnyHashable(“NSValidationErrorKey”): rating]

When I run the final version, I don’t get an error. Maybe your data is corrupt from a previous version of the app (I’m pretty sure any Bowtie project you open will use the same data file. Try resetting the simulator or deleting the data file.

AN, could you take more time (yes, know) to do this favor for me? Could you confirm you did exactly the following:

  1. Bring up the Bowtie app
  2. Select a bowtie (the default red one is fine to start with)
  3. Click “Rate”
  4. Enter 7 in the Alert dialog
  5. When the second alert dialog pops up, hit “Cancel”
  6. Then select a different bowtie.
  7. Click “Wear”… Confirm the “Wear” method does not increment the count
  8. Click the original bowtie, and check to see if the Rating now specifies “7.0”

If you see the above, then we’re on the same page. If you see the app behaving as desired, then I have something wrong local to my machine. I have wiped the app from the simulator many times to start fresh… But maybe there are other things I have neglected…

Would sincerely appreciate you taking the time.
Thanks!

Yes, you’re absolutely right. The Rating is 7 and generates a 1610 error. :confused:

@fr33rid3r
Sincerest THANKS for taking the time… It is precious these days.

So, you have confirmed what I am experiencing. Now for the troubleshooting.

Without paying attention to the code, I had suspected it was something to do with the UIAlertController, and how it deals with “CancelAction”; however, looking at the update method, it looks like that is the source of the issue. I’m looking for someone to comment on a best practice to resolve this flawed behavior.

How best could we get the attention of resources to help?

Thoughts? Thanks Again!