are extensions bad for performance in swift?

后端 未结 2 1866
春和景丽
春和景丽 2020-12-07 01:43

Swift offers the ability to write extensions. I do that a lot to make my code easier to read. Not sure if they are harmless. I am wondering, would it be better to just omit

2条回答
  •  醉梦人生
    2020-12-07 02:22

    You don't need to worry about that. Compiler while compiling, treat these extensions as much as like a just another function call. Because extension is not a dynamic behavior but a static one. When you use performSelector it costs more performance than a normal instance method or extension as it is a dynamic behavior.

提交回复
热议问题