Skip to content

Instantly share code, notes, and snippets.

@groue
Created July 24, 2015 14:46
Show Gist options
  • Save groue/ba3672ef7eb8024c9897 to your computer and use it in GitHub Desktop.
Save groue/ba3672ef7eb8024c9897 to your computer and use it in GitHub Desktop.
// Library code
class Model { }
protocol Fetchable {
typealias FetchableType = Self
static func fetchAll(sql: String) -> [FetchableType]
}
extension Fetchable where Self : Model, FetchableType == Self {
static func fetchAll(sql: String) -> [FetchableType] {
return [] // bare minimal, for demonstration purpose
}
}
extension Model : Fetchable { }
// Userland code
class Parent: Model { }
class Child: Parent { }
// error: cannot invoke 'fetchAll' with an argument list of type '(String)'
let parents = Parent.fetchAll("SELECT * FROM ...") // [Parent]
// error: cannot invoke 'fetchAll' with an argument list of type '(String)'
let children = Child.fetchAll("SELECT * FROM ...") // [Children]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment