-2

I have an array of Strings in my Swift app. I want to display them in a label, each of them separated by ,. I tried this:

for hashtag in placeHashtags {
        text = text + "\(hashtag), "
    }

if (placeHashtags.count > 0){
    let text1 = text.remove(at: text.index(before: text.endIndex-1))
    text = text1.description
}

(the 2nd if is to remove the last comma), but then I do not see anything in my label. How can I fix it?

2
  • 3
    Check this stackoverflow.com/questions/25827033/… Commented May 1, 2017 at 13:00
  • The actual problem in your code is that text.remove(at:) returns the removed character, not the modified string. Commented May 1, 2017 at 13:36

1 Answer 1

2

You should Write this:

let array = ["Hi", "Hello", "How", "Are", "You", "Fine"]
let joined = array.joined(separator: ", ")
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Pragnesh, I will accept it as soon as I can :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.