Last active
January 12, 2018 08:24
-
-
Save yunarta/8ff113d01f62728ed5ab9d139d055b69 to your computer and use it in GitHub Desktop.
EndPoint
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
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() |
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
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) | |
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
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