Skip to content

Instantly share code, notes, and snippets.

@an0
Last active August 29, 2015 14:27
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 an0/a3e2952017b5a7a0d4d0 to your computer and use it in GitHub Desktop.
Save an0/a3e2952017b5a7a0d4d0 to your computer and use it in GitHub Desktop.
Self Referential Limitation or Bug
final class Foo {
// static let _sharedInstance = self.init() // Why not work?
static let _sharedInstance = Foo()
static func sharedInstance() -> Self {
return _sharedInstance // Why 'Foo' is not convertible to 'Self'? It is `static` so `Self` can only be `Foo`. In fact since the class is final there won't be any subclasses at all.
// return self.init() // Why this works?
}
required init() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment