Jones Jones - 6 months ago 34
Swift Question

Generic parameter "Element" could not be inferred -- Swift

So I'm in an Xcode playground, trying to remove the last character from a string. I think it should be really simple, but my code isn't working.

let test = "Get rid of that L"
Array(test.characters).dropLast().joinWithSeparator("")


I get an error on the second line "Generic parameter "Element" could not be inferred"

Answer

Don't need the join bit, just do this:

let lastCharRemoved = String(test.characters.dropLast())