0

For example: Array like ["A12", 1, 2, "Test"]. My expected result should be able to bind in the textfield or else to get as string with component seperator (,)

3
  • would you like to get Strings only from the array? Commented Feb 28, 2018 at 10:59
  • Try using joinWithSeparator(",") it should return a string like "A12,1,2,Test" Commented Feb 28, 2018 at 10:59
  • It's not clear what the expected output is: an array of strings, or a string. Can you clarify this in the question? Maybe give an example of how your output should look? Commented Feb 28, 2018 at 11:30

2 Answers 2

2

First map the values to String values, and then just join them using separator that you like:

let description: String = ["A12", 1, 2, "Test"].map{ String(describing: $0) }.joined(separator: ", ")
print(description)
Sign up to request clarification or add additional context in comments.

Comments

0

You can get it done with this,

    let array: [Any] = ["A12", 1, 2, "Test"]
    let tmpArray = array.map({ return String(describing: $0)})
    let string = tmpArray.joined(separator: ",")
    print(string)

Comments

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.