2016-01-12 16 views
0

我想在swift中通过textension重写NSDictionary中的描述属性,但无法确定如何。这是在Objective-C使用类很容易的和常见的,我可以这样做,因为这:如何在swift中通过扩展重写NSDictionary中的描述属性?

@implementation NSDictionary (Log) 

- (NSString *)descriptionWithLocale:(id)locale 
{ 
    NSMutableString *retStr = [NSMutableString string]; 

    retStr = ... 

    return [retStr copy]; 
} 

@end 

我在试图迅速为:

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 

然后我不知道该怎么办。请帮助我〜。〜

回答

3
+0

同样在Objective-C,你应该 “避免分类方法名称冲突” - https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html –

+0

我明白了。所以我应该避免在Objective-C中制作“冲突方法名称类别”,尽管代码可能在当前实现中工作。在迅速,这个应该避免的功能不再存在了。谢谢! – herodolphin

+0

是的,确切地说。我将链接固定在Swift特有的答案中。 –

相关问题