Created
July 24, 2015 13:56
-
-
Save groue/0c59a4b3e5082da327e5 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 | |
} | |
} | |
// Userland code | |
class Parent: Model, Fetchable { } | |
class Child: Parent { } | |
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