switch语句赋值给NSlocalizedString

时间:2016-09-20 14:04:05

标签: iphone swift switch-statement case

如何将updateHeaderNotifications和DebugAlert分配给NSlocalizedString?我试图添加updateHeaderNotifications = Nslocalized("text_text")但它不起作用。谢谢你的帮助

private func initViewToCurrentState(pocketStatus: pocketStatus?) {
    if let status = pocketStatus {
        switch status {
        case .Created:
            **updateHeaderNotifications** ("text1")
            initpocketBeforeTripView()

        case .Paid: fallthrough
        case .Undone: fallthrough
        case .Aborted: fallthrough
        default:
            PocketRideService.sharedInstance.removeCachedRide()
            dismissViewControllerAnimated(false, completion: {
                DebugAlert.show("text")

            })
        }
    }
}

1 个答案:

答案 0 :(得分:0)

根据您的方法定义,您可以使用如下:

private func updateHeaderNotifications(bigNotify: String, smallNotify: String) {
    bigNotification.text = NSLocalizedString(bigNotify, comment: "bigNotify")//you can set any text for comment parameter
    smallNotification.text = NSLocalizedString(smallNotify, comment: "smallNotify")
}

并在您的switch声明中:

        case .Created:
        updateHeaderNotifications("text1", smallNotify: "text2")