Skip to content

Instantly share code, notes, and snippets.

@ashfurrow
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashfurrow/88cbd0b6de626706f853 to your computer and use it in GitHub Desktop.
Save ashfurrow/88cbd0b6de626706f853 to your computer and use it in GitHub Desktop.
Swift initializer problem
class A {
let i: Int
let j: Int
init (i: Int, j: Int) {
self.i = i
self.j = j
}
convenience init(i: Int) {
self.init(i: i, j: 0)
}
}
class B: A {
override init(i: Int, j: Int) {
super.init(i: i, j: j)
}
convenience init(i: Int) {
self.init(i: i, j: 0)
}
convenience init(ix: Int) {
self.init(i: ix, j: 0)
}
}
let b = B(i: 1) // "Missing argument for parameter 'j' in call"
let b = B(ix: 1) // Works fine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment