切换语句...案例后的预期模式:

时间:2017-08-22 14:25:57

标签: ios swift3

在我的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
    }
}

错误的图像: enter image description here

编辑:我已经尝试了所建议的内容(移动:)我还得到了另一个奇怪的错误,如下图所示: enter image description here

2 个答案:

答案 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":