+ 16
How to convert [String] to String in Swift (and more generally [Type] to Type)?
So I have this programm where I try to filter some values of a range with a function that I made and I get an Exception saying that it cannot convert [String] to String... How can I do it then?
4 Réponses
+ 16
Nomeh Uchenna Gabriel thank you for your answer but I figured it out I think I just needed to do it like this:
.filter({spy(x:String($0))})
(wrap the "filter" between () )
+ 14
Nomeh Uchenna Gabriel Yes you're right, thank you. But indeed I find type conversions in Swift pretty hard to manage sometimes because there are a lot (Type, [Type], Set <Type> etc) and there is a difference between String(a) and String(a)!...😕😕
+ 5
You can convert different types in different ways in swift
Eg:
var e = 3
var er = String(e)
print((er) is String)
...But this can only work on new variable not the main one
+ 2
You're having fatal errors instead