Skip to content

Instantly share code, notes, and snippets.

@yunarta
Last active January 12, 2018 08:24
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 yunarta/8ff113d01f62728ed5ab9d139d055b69 to your computer and use it in GitHub Desktop.
Save yunarta/8ff113d01f62728ed5ab9d139d055b69 to your computer and use it in GitHub Desktop.
EndPoint
class EndPoint {
}
protocol API {
func login()
}
class APIVersionOne: API {
func login() {
}
}
class APIBase: EndPoint {
private let api: API
init(_ api: API) {
self.api = api
}
func login() {
api.login()
}
}
func endPoint<E>(_ of: E.Type) -> E? where E: EndPoint {
return APIBase(APIVersionOne()) as? E
}
let ep = endPoint(APIBase.self)
ep?.login()
class EndPoint {
}
protocol API {
func login()
}
class APIVersionOne: API {
func login() {
}
}
class APIBase<T>: EndPoint where T: API {
var api: T?
}
func endPoint<E>(_ of: E.Type) -> E? where E: EndPoint {
return APIBase<APIVersionOne>() as? E
}
let test = APIBase<APIVersionOne>() as? APIBase<API>
let ep = endPoint(APIBase<API>.self)
protocol EndPoint {
}
protocol API: EndPoint {
func login()
}
class APIVersionOne: API {
func login() {
}
}
func endPoint<E>(_ of: E.Type) -> E? where E: EndPoint {
return APIVersionOne() as? E
}
let ep1 = endPoint(APIVersionOne.self)
let ep2 = endPoint(API.self)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment