How to create a String with format? How to create a String with format? ios ios

How to create a String with format?


I think this could help you:

let timeNow = time(nil)let aStr = String(format: "%@%x", "timeNow in hex: ", timeNow)print(aStr)

Example result:

timeNow in hex: 5cdc9c8d


nothing special

let str = NSString(format:"%d , %f, %ld, %@", INT_VALUE, FLOAT_VALUE, LONG_VALUE, STRING_VALUE)


let str = "\(INT_VALUE), \(FLOAT_VALUE), \(DOUBLE_VALUE), \(STRING_VALUE)"

Update: I wrote this answer before Swift had String(format:) added to it's API. Use the method given by the top answer.