Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to poseAsClass in Mac OS X 10.5 and higher?

Apple has deprecated NSObject's poseAsClass: method for OS X v10.5 and above. Is there another way to make class posing work?

like image 670
e.James Avatar asked Aug 17 '09 18:08

e.James


2 Answers

I don't think there is a class-level equivalent, but you can exchange the implementation of two methods, which was often the purpose of using poseAsClass: (of course, you can exchange more than one method if you need to override multiple methods in a class). You want method_exchangeImplementations in the Objective-C 2.0 runtime (#import objc/runtime.h). A word of warning: after calling method_exchangeImplementations, calling the 'new' method actually calls the original method definition.

like image 130
Barry Wark Avatar answered Oct 07 '22 12:10

Barry Wark


Lap Cat gives an alternative.

like image 32
mcandre Avatar answered Oct 07 '22 12:10

mcandre