0

i need to override assignment operator in swift = but unfortunately i am no success at that. I have gone through many articles but they just conclude that to overload = in swift is not possible!

Kindly share if there is any way to achieve that.

Thanks in advance. Happy coding.

Aman Gupta
  • 985
  • 1
  • 8
  • 18
  • 2
    Those articles that you read are correct: You simply can't override the assignment operator. – Martin R May 02 '18 at 08:33
  • is there any workaround ? – Aman Gupta May 02 '18 at 08:34
  • The linked-to Q&A has a reference to the documentation which clearly states that `=` cannot be overloaded. What kind of “workaround” are you thinking of? – Martin R May 02 '18 at 08:39
  • 1
    As a work around you could define your own operator e.g. `func *=*(target: inout T, source: U) { target = castUToTSomehow(source) }` However, if you explain why you need the override, perhaps we can provide a less horrible way of doing it. – JeremyP May 02 '18 at 10:15

0 Answers0