Development, Mac OS, Obj-C, Programming

Objective-C Swizzling without Side Effects

<tl;dr> Using method_exchangeImplementations results in a number of unexpected and dangerous side effects which in most cases you’ll want to avoid. You should use method_setImplementation and swizzle a C-style function instead to give yourself more control over your applications behaviour. </tl;dr>   Swizzling is an incredibly powerful, and incredibly dangerous, feature of Objective-C that in [...]

Mac OS, Obj-C, Programming, Unit Testing

Injecting data into Obj-C readonly properties

<tl;dr> If you want to inject data into an object that only has read-only properties, swizzle the synthesised getter function so you can inject the data you need at the point it’s accessed. For example </tl;dr>   I recently needed to set up some client side unit tests for our iOS receipt verification server. This [...]