DariusV
DariusV

Reputation: 2773

How to conform to NSCopying and implement copyWithZone in Swift 4?

I can't conform NSCopying protocol when I try to use the swift 3 way, My code is:

public func copy(with zone: NSZone? = nil) -> Any {
    return type(of:self).init(self)
}

But an error appears: Cannot call value of non-function type 'ProductType'

What is the problem here?

Upvotes: 4

Views: 1643

Answers (1)

DariusV
DariusV

Reputation: 2773

I just found the solution, change the function for:

public func copy(with zone: NSZone? = nil) -> Any {
     return Swift.type(of:self).init(self)
 }

Upvotes: 3

Related Questions