Updating the ReviewFormViewController class to save reviews
The Save button in the Review Form screen currently just prints the review to the Debug area when tapped. To save reviews, you’ll need to modify the onSaveTapped(_:)
method to save a review to the persistent store when the Save button is tapped. Follow these steps:
- Click the
ReviewFormViewController
file in the Project navigator. Add the following property to theReviewFormViewController
class before the outlet declarations to store the restaurant identifier:var selectedRestaurantID: Int?
- Create a
private
extension, move theonSaveTapped(_:)
method into it, and modify it as follows:private extension ReviewFormViewController { @IBAction func onSaveTapped(_ sender: Any) { var reviewItem = ReviewItem() reviewItem.rating = ratingsView.rating reviewItem.title = titleTextField.text reviewItem.name = nameTextField.text reviewItem.customerReview ...