Objective-C Runtime
The Objective-C Runtime Reference says:
“Deprecated” below means “deprecated in Mac OS X version 10.5 for 32-bit code, and disallowed for 64-bit code.”
and I would like to use class_setSu开发者_开发问答perclass in Max OS X version 10.5 even though I still can do it the compiler gives warning telling me its deprecated but it still builds and the Bundle is still usable.
My question is what would be the equivalent in Max OS X 10.5?
On a guess using it is probably not a good idea. I know with the shift towards 64 bit several things in the runtime changed and didn't have a replacement.
The docs even explicitly say not to touch, and doesn't give exception to that.
You can however use class_addMethod
to add functionality to a given preexisting class. However, that is also doable via categories.
You can use class_replaceMethod
to override a method as well, another possible method is to use a category (or class_addMethod
) to add a replacement method. Then using method_exchangeImplementations
you can swap them so as to have the original still available for calling.
In general though most of this is kinda dark voodoo, and unless you're comfortable with and willing to test a lot, I'd look for an alternative design.
There may not be a direct equivalent.
I know every time I've played with the class hierarchy at runtime I've been burned. You should be able to achieve the same results, albeit more verbosely via delegation, and I'd imagine that's what they want.
精彩评论