在我的switch语句中的每个case声明之后,XCode表明应该有一个预期的模式?
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
switch segue.identifier {
case: "SegueToCommentRating"
let commentRatingViewController = segue.destination as! CommentRatingViewController
commentRatingViewController.post = self.post
commentRatingViewController.delegate = self
case: "SegueToLogin"
let loginViewController = segue.destination as! LoginViewController
loginViewController.managedObjectContext = managedObjectContext
case: "SegueToEditCommentOrRating"
let commentRatingViewController = segue.destination as! CommentRatingViewController
commentRatingViewController.post = self.post
commentRatingViewController.userWillEdit = true
commentRatingViewController.delegate = self
default:
break
}
}
编辑:我已经尝试了所建议的内容(移动:)我还得到了另一个奇怪的错误,如下图所示:
答案 0 :(得分:5)
正确的代码是:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let string = segue.identifier {
switch string {
case "SegueToCommentRating":
let commentRatingViewController = segue.destination as! CommentRatingViewController
commentRatingViewController.post = self.post
commentRatingViewController.delegate = self
case "SegueToLogin":
let loginViewController = segue.destination as! LoginViewController
loginViewController.managedObjectContext = managedObjectContext
case "SegueToEditCommentOrRating":
let commentRatingViewController = segue.destination as! CommentRatingViewController
commentRatingViewController.post = self.post
commentRatingViewController.userWillEdit = true
commentRatingViewController.delegate = self
default:
break
}
}
}
只需将“:”移动到
比较的值之后答案 1 :(得分:2)
将case: "SegueToCommentRating"
更改为case "SegueToCommentRating":