转自自:http://chris.eidhof.nl/post/typesafe-url-routes-in-swift/
定义
extension Github : Moya { var baseURL: NSURL { return NSURL(string: "https://api.github.com") } var sampleData: String { switch self { case .Zen: return "Half measures are as bad as nothing at all." case .UserProfile(let name): return "{login: \"\(name)\", id: 100}" } } }
用法:
func url(route: Moya) -> NSURL { return route.baseURL.URLByAppendingPathComponent(route.path) }