3 回答
TA贡献1805条经验 获得超9个赞
copy()
copy()
func copy() -> Self {
return C()}copy()CSelf
func copy() -> Self {
return Self()}D()
func copy() -> C {
return C()}SelfC
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贡献1869条经验 获得超4个赞
protocol Copyable {
init(copy:Self)}extension Copyable {
func copy() -> Self {
return Self.init(copy: self)
}}TA贡献1804条经验 获得超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 关注
- 493 浏览
添加回答
举报
