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 關注
- 454 瀏覽
添加回答
舉報
