0

Thought it'd be convenient to use tuples to set CGPoint properties, but I can't seem to figure out what swift wants me to do:

infix operator = {associativity right precedence 150} // 1
extension CGPoint {
    static func =<T: FloatingPoint>(lhs: inout CGPoint, rhs: (T, T)){ // 2
        lhs = CGPoint(x: rhs.0, y: rhs.1) // 3
    }
}
  1. Expected operator name in operator declaration I can't find anything saying that I'm not allowed to override the assignment operator, but that's what this sounds like.

  2. Operator implementation without matching operator declaration Because the first line is invalid.

  3. Cannot invoke initializer for type 'CGPoint' with an argument list of type '(x: T, y: T)' Could get rid of this by casting to Double, but is that the right way to go about this?

GoldenJoe
  • 7,874
  • 7
  • 53
  • 92
  • 1
    Short answer: You *can't* overload the assignment operator. – Martin R Nov 22 '19 at 08:53
  • 1
    @GoldenJoe You could use property wrappers to achieve this. Use `wrappedValue` as `(Float, Float)` and `projectedValue` as the underlying `CGPoint`. – user1046037 Nov 25 '19 at 06:26
  • @user1046037Good suggestion. I had completely forgotten about these. Guess it's a good excuse as any to refresh myself. Thanks. – GoldenJoe Nov 25 '19 at 08:57

0 Answers0