Skip to content

Instantly share code, notes, and snippets.

@onmyway133
Last active June 7, 2019 10:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save onmyway133/0fcf8af3817c7d945515dbbc35b5b9b1 to your computer and use it in GitHub Desktop.
Save onmyway133/0fcf8af3817c7d945515dbbc35b5b9b1 to your computer and use it in GitHub Desktop.
Init in protocol extension.swift
protocol P {
init()
}
extension P {
init(something: AnyObject) {
self.init()
print("P")
}
}
struct A: P {
init() {
print("A")
}
}
@onmyway133
Copy link
Author

protocol P {
  init()
}

extension P {
  init(something: AnyObject) {
    self.init()
    print("P")
  }
}

class A: P {
  required init() {
    print("A")
  }
}

@onmyway133
Copy link
Author

protocol P: class {
  init(core: AnyObject)
}

extension P {
  init(something: AnyObject) {
    self.init(core: something)
    print("P")
  }
}

class A: P {
  required init(core: AnyObject) {
    print("A")
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment