Skip to content

Instantly share code, notes, and snippets.

@surajsau
Created March 4, 2020 07:24
Show Gist options
  • Save surajsau/53661659f470a19b7ac1ba87bd9c5547 to your computer and use it in GitHub Desktop.
Save surajsau/53661659f470a19b7ac1ba87bd9c5547 to your computer and use it in GitHub Desktop.
@propertyWrapper
struct GET<T: Decodable> {
private var url: URL
init(url: String) {
self.url = URL(string: url)!
}
var wrappedValue: Observer<T> {
get {
return { observer in
AF.request(self.url).validate()
.responseDecodable(of: T.self) { response in
observer(response)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment