我目前的进展是这样的:
I've defined
typealias
completion handlertypealias UserCompletionHandler = (_ object: User?, _ error: ApiError?) -> Void
And I've created a service function that is using this typealias
func login(email: String, password: String, completion: UserCompletionHandler) { // ... // this part here handles API call and parsing logic // ... completion(user, nil) }
completion(object: user, error: nil)
甚至更好的做法是使错误参数可选,这样我只需调用
completion(object: user)
问题在于我找不到一种改变typealias
定义以实现这一目的的方法。