Skip to content

Instantly share code, notes, and snippets.

@floriankrueger
Last active October 30, 2015 16:00
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 floriankrueger/b46505916e46a0f360fe to your computer and use it in GitHub Desktop.
Save floriankrueger/b46505916e46a0f360fe to your computer and use it in GitHub Desktop.
specialized subclass of generic superclass
import Foundation
struct Something {}
class Base<T> {
let something: T
init(something: T) {
self.something = something
}
}
class Sub: Base<Something> {
// whatever 'Sub' does
}
let instance = Sub(something: Something()) // 'Sub' cannot be constructed because it has no accessible initializers
@maheshmobile
Copy link

struct Something {}

class Base {
let something: T

init(something: T) {
    self.something = something
}

}

class Sub: Base {
override init(something: Something) {
super.init(something: something)
}
// whatever 'Sub' does
}

let instance = Sub(something: Something())

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