Implementing copy() in Swift
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to be able to copy a custom class in Swift. So far, so good. In Objective-C I just had to implement the NSCopying protocol, which means implementing copyWithZone . As an example, I have a basic class called Value which stores a NSDecimalNumber . func copyWithZone(zone: NSZone) -> AnyObject! { return Value(value: value.copy() as NSDecimalNumber) } In Objective-C I, could easily just call copy to copy my object. In Swift, there seems to be no way to call copy . Do I really need to call copyWithZone even if no zone is needed? And which