uchicago-mobi / MPCS51030-2019-Spring-Forum

This repository will contain code examples and discussion topics for the winter 2019 quarter.
1 stars 1 forks source link

'archiveRootObject(_:toFile:)' and 'unarchiveObject(withFile:)' warnings #5

Closed landonjmitchell closed 5 years ago

landonjmitchell commented 5 years ago

I receive the following warnings in MealTableViewController.swift:

In the saveMeals function on the line: let isSuccessfulSave = NSKeyedArchiver.archiveRootObject(meals, toFile: Meal.ArchiveURL.path) I receive the warning:

'archiveRootObject(_:toFile:)' was deprecated in iOS 12.0: Use +archivedDataWithRootObject:requiringSecureCoding:error: instead

In the loadMeals function on the line: return NSKeyedUnarchiver.unarchiveObject(withFile: Meal.ArchiveURL.path) as? [Meal] I receive the warning:

'unarchiveObject(withFile:)' was deprecated in iOS 12.0: Use +unarchivedObjectOfClass:fromData:error: instead

I tried to do a little research to understand how to correct these issues, but am not confident I know how to implement the changes. Any guidance would be appreciated.

hbennett766 commented 5 years ago

A few things here. The assignment this week only requires you to complete the tutorial through the "Work with View Controllers" section. Persisting data is beyond the requirements. Second, you've got some missing files in your repo, which causes build errors when I download your project. Check out what you're missing, and make sure everything is pushed properly.

To answer the direct question here, that warning is just telling you that Apple has updated the method signature, from the (outdated) tutorial version to the version the compiler is suggesting. Sometimes, if you tap on the inline warning icon, the compiler will provide "fix this" suggestions that it can apply to the code for you. If not, the documentation will specify the correct way to write the method. For now, don't worry about it, since you're already beyond the requirements for the assignment.

landonjmitchell commented 5 years ago

Thanks for the reply. Guess I should have read the assignment instructions a little more closely. I’ll have to look into the missing files.

(Unfortunately there was no ‘fix this’ option for these errors. I will have to look into the documentation again)