如何通过 swift 中的扩展重写 NSDictionary 中的描述 属性?
How to rewrite description property in NSDictionary by extension in swift?
我想通过 swift 中的 textension 重写 NSDictionary 中的描述 属性,但不知道该怎么做。通过使用类别,这在 Objective-C 中非常简单和常见,我可以这样做:
@implementation NSDictionary (Log)
- (NSString *)descriptionWithLocale:(id)locale
{
NSMutableString *retStr = [NSMutableString string];
retStr = ...
return [retStr copy];
}
@end
我在 swift 中试过:
extension NSDictionary {
override public var description: String {
get {
return ...
}
}
}
但我失败了,因为:
Method 'description()' with Objective-C selector 'description' conflicts with getter for 'description' with the same Objective-C selector
那我就不知道怎么办了。请帮帮我~.~
我想通过 swift 中的 textension 重写 NSDictionary 中的描述 属性,但不知道该怎么做。通过使用类别,这在 Objective-C 中非常简单和常见,我可以这样做:
@implementation NSDictionary (Log)
- (NSString *)descriptionWithLocale:(id)locale
{
NSMutableString *retStr = [NSMutableString string];
retStr = ...
return [retStr copy];
}
@end
我在 swift 中试过:
extension NSDictionary {
override public var description: String {
get {
return ...
}
}
}
但我失败了,因为:
Method 'description()' with Objective-C selector 'description' conflicts with getter for 'description' with the same Objective-C selector
那我就不知道怎么办了。请帮帮我~.~