Created
July 24, 2015 14:46
-
-
Save groue/ba3672ef7eb8024c9897 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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