在UNIREST中,将这样完成:
extension ObservableNotification {
static func addOneTimeObserver(to center: NotificationCenter, using block: @escaping (Self)->Void) -> NotificationToken {
var token: NotificationToken!
token = addObserver(to: center) {
block($0)
token.reset()
}
return token
}
}
-
我现在拥有的代码如下,我想用上面的Unirest代替restTemplate做同样的事情。
HttpResponse<String> response = Unirest.put(apiUrl + "/photos/" + photo.getId()).headers(standardHeaders()).body("{ \"status\": \"" + status + "\" }").asString();
if (response.getStatus() != 200) {
log.error("Status " + response.getStatus() + " returned from CloudCard API when updating photo.");
return null;
}
return new ObjectMapper().readValue(response.getBody(), new TypeReference<Photo>() {
})