0

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 ?

4
  • Is there a stringWithFormat function instead of localizedStringWithFormat? Commented May 6, 2016 at 23:45
  • @rmaddy no there is no stringWithFormat function in String Commented May 6, 2016 at 23:47
  • Try let url = SERVER_URL + String.localizedStringWithFormat(GET_LISTING, deviceId, String(listingId)); Commented May 6, 2016 at 23:48
  • There is a String(format:, arguments:) constructor in swift. Also, you should consider using String interpolation: "Listing/GetDetails?deviceid=\(deviceId)&listingid=\(listingId)" Commented May 6, 2016 at 23:52

1 Answer 1

4

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))
Sign up to request clarification or add additional context in comments.

2 Comments

you mean let GET_LISTING = "Listing/GetDetails?deviceid=%@&listingid=%@"
Sure. I thought %s would work, but %@ certainly should. Changed it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.