+ 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?

15th Jul 2018, 8:49 AM
Uni
Uni - avatar
4 Antworten
+ 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 () )
16th Jul 2018, 6:52 AM
Uni
Uni - avatar
+ 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)!...😕😕
16th Jul 2018, 8:01 AM
Uni
Uni - avatar
+ 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
16th Jul 2018, 6:56 AM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
+ 2
You're having fatal errors instead
16th Jul 2018, 6:36 AM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar