0

I'm trying to concatenate an array of string-backed enums into one single string. I have the following

enum MyEnumType1: String {
    case Foo = "foo"
    case Bar = "bar"
}

and this method to retrieve a string from an array of string-backed enums.

func getConcatenatedStringFromArray(array: [MyEnumType1]) -> String {
    return array.joinWithSeparator(",")
}

I get a compile error stating an Ambiguous reference to it's member "joinWithSeparator". How what am i doing wrong?

1
  • If my answer was helpful please consider to accept it. Commented Oct 1, 2015 at 14:50

1 Answer 1

2

You should map your array to array of strings:

func getConcatenatedStringFromArray(array: [MyEnumType1]) -> String {
    return array.map { $0.rawValue }.joinWithSeparator(",")
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.