Objective-C 运行时
下面的“已弃用”表示“在 Mac OS X 版本 10.5 中已弃用 32 位代码,并且不允许使用 64 位代码。”
我想在 Max OS X 版本 10.5 中使用 class_setSuperclass,即使我仍然可以这样做,编译器会发出警告,告诉我它已弃用,但它仍然可以构建,并且 Bundle 仍然可用。
我的问题是 Max OS X 10.5 中的等效项是什么?
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_setSuperclass 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
猜测使用它可能不是一个好主意。我知道随着向 64 位的转变,运行时中的一些事情发生了变化,并且没有替代品。
文档甚至明确表示不要触摸,并且没有例外。
但是,您可以使用
class_addMethod
向给定的预先存在的类添加功能。然而,这也可以通过类别来实现。您也可以使用
class_replaceMethod
来重写方法,另一种可能的方法是使用类别(或class_addMethod
)来添加替换方法。然后使用method_exchangeImplementations
您可以交换它们,以便原始版本仍然可用于调用。总的来说,尽管其中大部分都有点黑暗巫术,除非您对此感到满意并愿意进行大量测试,否则我会寻找替代设计。
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 (orclass_addMethod
) to add a replacement method. Then usingmethod_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.