【问题标题】:how to detect is NSMutableAttributedString attribute NSStrikethroughStyleAttributeName available to use?如何检测 NSMutableAttributedString 属性 NSStrikethroughStyleAttributeName 是否可用?
【发布时间】:2013-08-15 14:03:49
【问题描述】:
我的意思是检测我是否能够使用属性 NSStrikethroughStyleAttributeName ofNSMutableAttributedString 喜欢:
if ([object responseToSelector:@selector(someSelector)])
或喜欢:
if ([SomeNewClass class])
我不想比较系统版本,但我不想准确检查这个项目;
【问题讨论】:
标签:
ios
objective-c
nsmutablestring
【解决方案1】:
NSStrikethroughStyleAttributeName 适用于 iOS 6,因此如果您支持 6 或更高版本,则无需担心。
Apple 也使用weak linking。这会将当前版本的操作系统中不可用的符号设置为NULL。因此,您可以测试该符号以查看它是否存在:
if (NSStrikethroughStyleAttributeName != nil) {
// use NSStrikethroughStyleAttributeName
}