ios - Ambiguous error when attempting to filter values using enum -
i have filter trying use compare 1 value another. here enum using:
enum someenum: string { case first = "hey" case second = "there" case third = "peace" static let values = [first, second, third] func pickone() -> string { switch self { case .first: return "value 1" case .second: return "value 2" case .third: return "value 3" } }
here attempting filter , find matching values:
array.append(someenum.values.filter({$0.rawvalue == anotherarray["id"] as! string}))
i end getting ambiguous error:
cannot convert value of type '[someenum]' expected argument type 'string'
any ideas?
the problem is, someenum.values
return type [someenum]
, not string
.
and append
function expects parameter string
, instead [someenum]
.
this is, need change:
- change
append
appendcontentsof
, sincefilter
function returns array, , not single value - change
[someenum]
[string]
since adding[string]
array, this.
this fix:
array.appendcontentsof(someenum.values.filter({ $0.rawvalue == "somestring" }).map({ $0.pickone() }))
Comments
Post a Comment