Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

are extensions bad for performance in swift?

Tags:

ios

swift

swift2

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 extensions, because of performance reasons?

like image 599
potato Avatar asked Oct 01 '15 18:10

potato


2 Answers

Apple encourages the use of extensions. You can read more about them on the Swift documentation here.

like image 100
Charles Truluck Avatar answered Sep 28 '22 11:09

Charles Truluck


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.

like image 38
jblixr Avatar answered Sep 28 '22 12:09

jblixr