基于操作系统版本的条件方法
我确信这真的很简单,但我什至不确定如何搜索它,因为我已经看到了我认为所谓的编译器标志的示例?,但一般来说,可可中有条件地运行特定的最佳方法是什么方法在支持它的操作系统版本上。例如,NSDateFormatter 类具有 setDoesRelativeDateFormatting 方法,该方法仅适用于 10.6(在 Mac 上)及更高版本。
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSLocale *enLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormatter setLocale:enLocale];
[dateFormatter setDoesRelativeDateFormatting:YES];
I am sure this is really simple, but I'm not sure even how to search for it, as I have seen example of what I think are called compiler flags?, but in general whats the best method in cocoa of condtionally running a specific method on Operating System Versions that support it. as an example the NSDateFormatter Class has the setDoesRelativeDateFormatting method which only works on 10.6 (on the Mac) and higher.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSLocale *enLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormatter setLocale:enLocale];
[dateFormatter setDoesRelativeDateFormatting:YES];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是 Adium 如何检测到它正在 Snow Leopard 上运行,或者更好地执行类似的操作(这是 NSApplication 上的一个类别):
然后您所要做的就是
您可以通过命令单击 NSAppKitVersionNumber 来找到 AppKit 的版本号跳转到它的定义。
Here's how Adium detected that it was running on Snow Leopard or better to do stuff like this (this was in a category on NSApplication):
Then all you have to do is
You can find the version numbers for AppKit by command-clicking on NSAppKitVersionNumber to jump to its definition.
对于这种特殊情况,执行以下操作应该很容易:
请参阅
NSObject
协议的-respondsToSelector:
了解更多信息。For this particular case, it should be easy enough to do the following:
See
NSObject
protocol's-respondsToSelector:
for more info.