简体   繁体   中英

are extensions bad for performance in swift?

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM