1. 程式人生 > >[iOS] swift : use of %s in String(format: …)

[iOS] swift : use of %s in String(format: …)

Apple 官方檔案:

使用範例:

"IdelTimeOutMessage" = "Idle time out exceeded, please input your password for account:%[email protected]";

附註:請使用 %@ , 不要用 %s ,不然會 crash

完整的範例:

let idleTimeoutMessage = String(format: NSLocalizedString(“IdelTimeOutMessage”, comment: “”), user_id)

let alert:UIAlertController =

UIAlertController(title: NSLocalizedString(“Alert”, comment: “”),

message: idleTimeoutMessage,

preferredStyle: UIAlertControllerStyle.alert)

let defaultAction:UIAlertAction = UIAlertAction(title: “OK”,

style: UIAlertActionStyle.default,

handler:{

(action:UIAlertAction!) -> Void in

print(“OK”)