2016-01-12 17 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特有的答案中。 –

相關問題