Suppose I'd like to read a value from UseDefaults, if it fails, try to ask server for it , I wrote this code, but it will not execute:
func getAuthorizationCode() -> SignalProducer<String, MoyaError> {
if let authCode = UserDefaults.string(forKey: .authorizationCode) {
return SignalProducer(value: authCode)
}
let provider = ReactiveSwiftMoyaProvider<UserService>()
return provider.request(.authorization).flatMap(.concat) {
response -> SignalProducer<String, Moya.MoyaError> in
let json = JSON(data: response.data)
log.debug("Authorization response:\(json) ")
let authCode = json["authorizationcode"].stringValue
return SignalProducer(value: authCode)
}
}
getAuthorizationCode().start { event in case let .value(value): print(value) case let .failed(error): print(error) } What's more, If I'd like to execute another network request, what should I do?
Any help is appreciated.