Swift is a precompiled language, and all objects are converted to memory addresses; however, there is a special "Selector" in Swift that allows functions to be found by function names at runtime. How did this work? Does this mean that naming functions will affect operational efficiency?
No, function names do not meaningfully affect performance in Swift.
Function and method names are used in two primary ways once compiled into your program:
#selector(...)), the unique selector is pre-compiled in to your program, so the name never needs to be looked up at runtime, and the selector pointer itself can instead be used directly when calling methodsNSSelectorFromString(...)), the selector is looked up from the given name dynamically (in a global table of unique selectors), and if not found, a new selector is dynamically created at runtimeIn both case (1) and (2a), the name of the function is never really used in the process of making the call, and is irrelevant. In case (2b), it technically is (for selector lookup), but the process is so fast that it really doesn't matter. Method names are rarely long, since they are most often typed by hand, and compared to most operations a program can perform, even the most dynamic use-case (looking up methods manually at runtime) is so insignificant that you really shouldn't worry about it.
One other consideration: when you compile a program with symbols embedded in it, those symbols take up space in your binary. You shouldn't really worry about that either because:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With