by
0 6

Prototype pattern.  Copying protocol

Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/3810759/Prototype-pattern---Copying-protocol?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// Enter here the actual content of the snippet. public protocol Copying: class { init(_ prototype: Self) } extension Copying { public func copy() -> Self { return type(of: self).init(self) } } extension Array where Element: Copying { public func deepCopy() -> [Element] { return map { $0.copy() } } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus