Martin Sosna Martin Sosna - 2 months ago 20
Swift Question

switch statement assign to NSlocalizedString

How can I assign updateHeaderNotifications and DebugAlert to NSlocalizedString? I tried to add updateHeaderNotifications = Nslocalized("text_text") but it doesnt work. Thanks for help

private func initViewToCurrentState(rideStatus: RideStatus?) {
if let status = rideStatus {
switch status {
case .Created:
**updateHeaderNotifications** ("text1")
initRouteBeforeTripView()
case .Accepted:
initRouteBeforeTripView()
case .DriverInPlace:
initDriverIsWaitingView()
case .Started:
initRouteOnTripView()
case .Paid: fallthrough
case .Completed: fallthrough
case .Aborted: fallthrough
default:
PassengerRideService.sharedInstance.removeCachedRide()
dismissViewControllerAnimated(false, completion: {
DebugAlert.show("text")

})
}
}
}

Answer

Based on your method definition, you can use like below:

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")
}

and in your switch statement:

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