ios - format String with array of Strings -


i trying create string array of strings, expect work:

let format = "%@ , %@!" let str1 = "bla" let str2 = "blob"  private func formatitnicely(format: string, substrings: [string]) -> string {     return string(format: format, arguments: substrings) }  let result = formatitnicely(format, substrings: [str1, str2]) 

but getting fatal error: can't unsafebitcast between types of different sizes.

i have seen this , this , this questions (and many more), still don't know how accomplish trying do.

string(format:, arguments: ) expects [cvarargtype] second parameter:

let format = "%@ , %@!" let str1 = "bla" let str2 = "blob"  private func formatitnicely(format: string, substrings: [cvarargtype]) -> string {     return string(format: format, arguments: substrings) }  let result = formatitnicely(format, substrings: [str1, str2]) print(result) // bla , blob! 

but note can crash (or give unexpected output) if format specifiers not match actual arguments, formatting functions not (cannot) check that.


Comments