swift - How to use String object in the String format class method -


suppose have string object in swift , want use string format class method combine , several other objects this:

var foo = 0 var str = "str" string(format: "%d (%s)", foo, str) 

this example doesn't work expected because %s can't handle string objects. how can then?

thanks in advance.

string(format:) bridged -[nsstring initwithformat] method , accepts same format specifiers, such %@ objects. string bridged nsstring automatically, therefore can use %@ swift strings well. note swift int type corresponds long in c:

var foo = 0 var str = "str" let result = string(format: "%ld (%@)", foo, str) 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -