Skip to content

Instantly share code, notes, and snippets.

@ncooke3
Created February 1, 2020 23:47
Show Gist options
  • Save ncooke3/b11ce58110d02c2320771a27d61f007b to your computer and use it in GitHub Desktop.
Save ncooke3/b11ce58110d02c2320771a27d61f007b to your computer and use it in GitHub Desktop.
Simple Objective-C API Call
- (NSString *)fetchData {
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"GET"];
[request setURL:[NSURL URLWithString:stringURL]];
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data,
NSURLResponse * _Nullable response,
NSError * _Nullable error) {
NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Data received: %@", myString);
}] resume];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment