无法检查函数的引用相等性;这里的操作数有类型 'UIBarButtonItem' 和 '(UIBarButtonItem) -> ()'

Cannot check reference equality of functions; operands here have types 'UIBarButtonItem' and '(UIBarButtonItem) -> ()'

我正在尝试 this Apple tutorial 但我发现了一个错误。有人可以帮助我吗?

Disable Saving When the User Doesn't Enter an Item Name

What happens if a user tries to save a meal with no name? Because the meal property on MealViewController is an optional and you set your initializer up to fail if there’s no name, the Meal object doesn’t get created and added to the meal list—which is what you expect to happen. But you can take this a step further and keep users from accidentally trying to add meals without a name by disabling the Save button while they’re typing a meal name, and checking that they’ve specified a valid name before letting them dismiss the keyboard.

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    super.prepare(for: segue, sender: sender)
    
    // Configure the destination view controller only when the save button is pressed.
    guard let button = sender as? UIBarButtonItem, button === saveButton else {
        if #available(iOS 10.0, *) {
            os_log("The save button was not pressed, cancelling", log: OSLog.default, type: .debug)
        } else {
            // Fallback on earlier versions.
        }
        return
    }
    
    let name = nameTextField.text ?? ""
    let photo = photoImageView.image
    let rating = ratingControl.rating
    
    // Set the meal to be passed to MealTableViewController after the unwind segue.
    meal = Meal(name: name, photo: photo, rating: rating)
}

您可能对 saveButton 属性 声明有疑问。它应该输入为 UIBarButtonItem(而不是 (UIBarButtonItem) -> Void,如您的错误所示)。

为了安全起见,请尝试重复 Apple 教程中的将保存按钮连接到 MealViewController 代码 步骤。