10.5基础SDK,10.4部署:如何实现缺失的方法

发布于 2024-07-22 06:30:04 字数 285 浏览 1 评论 0原文

我有一个针对 Mac OS X 10.4 和 10.5 的项目,其中 10.5 是基础 SDK。

一些方法,例如 -[NSString stringByReplacingOccurrencesOfString:withString] 在 10.4 中不可用。 我可以手动实现该功能。 另一种选择是将该方法实现为一个类别,但这会扰乱 10.5 的实现,这是我想避免的。

那么我如何在 10.4 中实现这些方法而不弄乱 10.5,并且当我决定停止支持 10.4 时可以轻松地取出实现呢?

I have a project that targets both Mac OS X 10.4 and 10.5, where 10.5 is the base SDK.

Some methods like -[NSString stringByReplacingOccurrencesOfString:withString] are unavailable in 10.4. I could just implement the functionality by hand. Another option would be to implement the method as a category, but that would mess with the 10.5 implementation and that's something I'd like to avoid.

So how do I implement such methods in 10.4 without messing up 10.5 and in such a way that I can take out the implementation easily when I decide to stop supporting 10.4?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

惜醉颜 2024-07-29 06:30:04

I think you have to use +load and +initialize to load a method at runtime if the method doesn't already exists.

遗忘曾经 2024-07-29 06:30:04
if ([myString respondsToSelector: @selector(stringByReplacingOccurrencesOfString:withString:)])
{
  // 10.5 implementation
}
else
{
  // 10.4 implementation
}
if ([myString respondsToSelector: @selector(stringByReplacingOccurrencesOfString:withString:)])
{
  // 10.5 implementation
}
else
{
  // 10.4 implementation
}
清旖 2024-07-29 06:30:04

使用类别,但在方法名称上放置标签; 例如,stringByReplacingOccurrencesOfString_TigerCompatible:。 在实现中,调用 Leopard 的实现或您自己的实现。

当您仅使用 Leopard 时,请进行项目搜索“TigerCompatible”,然后烧录所有这些方法并取消标记所有调用站点。

Use a category, but put a tag on the method name; for example, stringByReplacingOccurrencesOfString_TigerCompatible:. In the implementation, call either Leopard's implementation or your own.

When you go Leopard-only, do a project search for “TigerCompatible”, then burninate all of those methods and un-tag all of their call sites.

不再让梦枯萎 2024-07-29 06:30:04

如果在 Tiger 下运行,则将所有缺少的实现放在一个包中的类别中,该包在启动时加载到 main() 中。

Put all the missing implementation in categories in a bundle which is loaded on startup in main() if running under Tiger.

只等公子 2024-07-29 06:30:04

如果是为 10.4 构建的,那么使用 C 预处理器宏来插入相关方法怎么样? 也许尝试在类别中执行类似的操作,这样 10.4 上不存在的那些方法仅在为 10.4 构建时才包含在内?

#if defined(MAC_OS_X_VERSION_10_4) && MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
// Put your implementations of the methods here
#endif

How about using a C preprocessor macro to insert the relevant methods if it's being built for 10.4? Maybe try doing something like this in a category, so those methods which don't exist on 10.4 are only included if it's being built for 10.4?

#if defined(MAC_OS_X_VERSION_10_4) && MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
// Put your implementations of the methods here
#endif
感情旳空白 2024-07-29 06:30:04

需要支持10.4吗? 如果您在应用程序的核心部分仅使用 10.5 的方法,那么可能是时候考虑仅使用 10.5 了。

无论如何,根据上面给出的具体示例,我建议摆脱这种情况并制作字符串的可变副本,以便您可以在 NSMutableString 上使用类似的方法,该方法在 10.4 中有效

Do you need to support 10.4? If you're using 10.5 only methods in core parts of your app then it might be time to consider going 10.5 only.

Anyway, with the specific example given above, I suggest moving away from that and making a mutable copy of your string so you can use the similar method on NSMutableString which does work in 10.4

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文