3 回答

TA贡献1765条经验 获得超5个赞
copy()
copy()
func copy() -> Self { return C()}
copy()
C
Self
func copy() -> Self { return Self()}
D()
func copy() -> C { return C()}
Self
C
copyWithZone:
NSCopying
func copy() -> AnyObject!
protocol Copyable { func copy() -> AnyObject}
protocol Copyable { func copy() -> Copyable}
protocol Copyable { init(copy: Self)}class C : Copyable { required init(copy: C) { // Perform your copying here. }}
dynamicType
protocol Copyable { func copy() -> Self init(copy: Self)}class C : Copyable { func copy() -> Self { return self.dynamicType(copy: self) } required init(copy: C) { // Perform your copying here. }}

TA贡献1796条经验 获得超4个赞
protocol Copyable { init(copy:Self)}extension Copyable { func copy() -> Self { return Self.init(copy: self) }}

TA贡献1775条经验 获得超8个赞
public protocol Creatable { associatedtype ObjectType = Self static func create() -> ObjectType}class MyClass { // Your class stuff here}extension MyClass: Creatable { // Define the protocol function to return class type static func create() -> MyClass { // Create an instance of your class however you want return MyClass() }}let obj = MyClass.create()
- 3 回答
- 0 关注
- 354 浏览
添加回答
举报