I really do not recommend doing this, but Objective-C allows you to extend the setObject:atIndexedSubscript: method using native code. This process is called the "swizzling method" and it is explained here: http://darkdust.net/writings/objective-c/method-swizzling
Here is the actual working code demonstrating this process. The cold bit is in main() , where I can use fib[-1] = ... instead of fib[fib.count] = ... Of course, there is no huge advantage; the code is no more efficient and certainly harder to read. But I still need to record " fib " twice.
The main drawback of this approach is that Objective-C doesnโt actually have rules on the order in which categories are loaded, so if someone else provided a category with similar functionality, it would be dreary which one was last loaded. (And if they accidentally chose the same name for their category, I would think that it would be a throw that loaded at all.)
So, on the bottom line, do not do this: but it is possible.
source share