Amira Elsayed Ismail Amira Elsayed Ismail - 7 months ago 26
Swift Question

iOS String format

I have the following issue in swift

I have a String

let GET_LISTING = "Listing/GetDetails?deviceid=%@&listingid=%d";


the I use this line to get it formatted

let url = SERVER_URL + String.localizedStringWithFormat(GET_LISTING, deviceId, listingId);


when the number < 1000 it works fine

for example

Listing/GetDetails?deviceid=AB11F1D0-153E-48C3-950F-CC773BBCC683&listingid=500


if number > 1000 it is wrong

Listing/GetDetails?deviceid=AB11F1D0-153E-48C3-950F-CC773BBCC683&listingid=1,050


how can I solve this problem ?

Answer

You could convert the listingId to a String:

let GET_LISTING = "Listing/GetDetails?deviceid=%@&listingid=%@"
let url = SERVER_URL + String.localizedStringWithFormat(GET_LISTING, deviceId, String(listingId))