dimasjt
dimasjt

Reputation: 180

no exact matches in call to instance method 'append'

I'm creating Native Module for React Native. I'm trying to process the data in Swift, here's the function

enter image description here

func getCornerPoints(_ cornerPoints: [AnyHashable]?) -> [AnyHashable]? {
    var result: [AnyHashable] = []
    
    if cornerPoints == nil {
      return result
    }
    for point in cornerPoints ?? [] {
      guard let point = point as? NSValue else {
        continue
      }
      var resultPoint: [AnyHashable: Any] = [:]
      resultPoint["x"] = NSNumber(value: Float(point.cgPointValue.x))
      resultPoint["y"] = NSNumber(value: Float(point.cgPointValue.y))
      
      result.append(resultPoint) // error is here "No exact matches in call to instance method 'append'"
    }
    return result
  }

Upvotes: 1

Views: 9220

Answers (1)

vadian
vadian

Reputation: 285092

Any does not conform to Hashable therefore [AnyHashable: Any] (variable resultPoint) cannot be represented by AnyHashable.

But why is the value of resultPoint Any at all? It's clearly NSNumber. If you declare resultPoint

var resultPoint: [AnyHashable: NSNumber] = [:]

then the code compiles.

And why is the return type optional? result is – also clearly – non-optional

Upvotes: 2

Related Questions