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:

  1. change append appendcontentsof, since filter function returns array, , not single value
  2. change [someenum] [string] since adding [string] array, this.

this fix:

array.appendcontentsof(someenum.values.filter({ $0.rawvalue == "somestring" }).map({ $0.pickone() })) 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -