Unable to convert Substring value to expected String argument type - Swift 4

Trying to get a substring String and add it to an array of strings:

var stringToSplit = "TEST TEXT" var s = [String]() let subStr = anotherString[0 ..< 6] s.append(subStr) // <---- HERE I GET THE ERROR 

error desc

+5
source share
1 answer

As @Leo Dabus mentioned, you need to initialize a new String with substring :

Edit:

 s.append(subStr) 

To:

 s.append(String(subStr)) 
+12
source

Source: https://habr.com/ru/post/1272028/


All Articles