How to convert an Array to a String in Swift?
Hello everyone! I'm new to Swift, writing my first iOS app. I ran into what seemed like a simple task: I have an array of strings, and I want to output its contents to a UILabel or in print for debugging. But instead of a nice string like "apple, banana, orange", Xcode gives an error or prints something unclear.
Here's an example of my code:
```swift
let fruits = ["apple", "banana", "orange"]
let result: String = fruits // Error: Cannot assign value of type '[String]' to type 'String'
print(fruits) // Prints: ["apple", "banana", "orange"] — not what I need
```
I understand that an array is not a string, but how can I join all elements into one string with separators? I tried writing it manually using a for loop, but it looks bulky and ugly. Surely Swift has a built-in
No answers yet.
Log in to leave an answer