Avatar ·

How to split a string into an array in Swift? (Split String into Array)

Hi everyone! I'm new to Swift and can't figure out how to properly split a string into an array of strings. For example, I have a string: ```swift let text = "apple,banana,orange,grape" ``` I need to get an array: ```swift ["apple", "banana", "orange", "grape"] ``` I tried using the `components(separatedBy:)` method, but it's only available for `NSString`. And in Swift, as far as I know, strings are `String`. I also heard about `split`, but it returns `Array`, and I need regular `String` because I will work with them further, passing them to functions that accept `String`, not `Substring`. Please advise how to correctly and efficiently split a string into an array of strings in Swift? Is there a standard method for this? And how to get rid of `Su