Skip to content

Commit

Permalink
Fix nullability warnings/errors
Browse files Browse the repository at this point in the history
Summary: ^

Reviewed By: passy

Differential Revision: D50640020

fbshipit-source-id: d42b938520203a6ce232717c1adc43da176457e3
  • Loading branch information
lblasa authored and facebook-github-bot committed Oct 25, 2023
1 parent da7917c commit 7f6d1cf
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 35 deletions.
87 changes: 54 additions & 33 deletions iOS/Sample/NetworkViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,32 @@ - (void)viewDidLoad {
}

- (IBAction)tappedGithubLitho:(UIButton*)sender {
[[[NSURLSession sharedSession]
dataTaskWithURL:
[NSURL
URLWithString:
@"https://raw.githubusercontent.com/facebook/litho/main/docs/static/logo.png"]
completionHandler:^(
NSData* _Nullable data,
NSURLResponse* _Nullable response,
NSError* _Nullable error) {
if (error && !data) {
return;
}
NSLog(@"Got Image");
}] resume];
NSURL* url = [NSURL
URLWithString:
@"https://raw.githubusercontent.com/facebook/litho/main/docs/static/logo.png"];
if (!url) {
return;
}

[[[NSURLSession sharedSession] dataTaskWithURL:url
completionHandler:^(
NSData* _Nullable data,
NSURLResponse* _Nullable response,
NSError* _Nullable error) {
if (error && !data) {
return;
}
NSLog(@"Got Image");
}] resume];
}

- (IBAction)tappedPOSTAPI:(UIButton*)sender {
NSString* post = @"https://demo9512366.mockable.io/FlipperPost";
NSURL* url = [NSURL URLWithString:post];
NSURL* url =
[NSURL URLWithString:@"https://demo9512366.mockable.io/FlipperPost"];
if (!url) {
return;
}

NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[urlRequest addValue:@"application/json" forHTTPHeaderField:@"Accept"];
Expand All @@ -57,42 +64,56 @@ - (IBAction)tappedPOSTAPI:(UIButton*)sender {
[[[NSURLSession sharedSession]
dataTaskWithRequest:urlRequest
completionHandler:^(
NSData* _Nullable data,
NSData* data,
NSURLResponse* _Nullable response,
NSError* _Nullable dataTaskError) {
if (dataTaskError || !data) {
if (dataTaskError) {
[weakSelf
showAlertWithMessage:@"Received error in POST API response"];
return;
}
NSDictionary* dict =
[NSJSONSerialization JSONObjectWithData:data
options:0
error:&dataTaskError];
NSLog(@"MSG-POST: %@", dict[@"msg"]);
if (data == nil) {
[weakSelf
showAlertWithMessage:@"No data received in POST API response"];
} else {
NSDictionary* dict =
[NSJSONSerialization JSONObjectWithData:data
options:0
error:&dataTaskError];
NSLog(@"MSG-POST: %@", dict[@"msg"]);

[weakSelf showAlertWithMessage:@"Received response from POST API"];
[weakSelf showAlertWithMessage:@"Received response from POST API"];
}
}] resume];
}

- (IBAction)tappedGetAPI:(UIButton*)sender {
NSURL* url =
[NSURL URLWithString:@"https://demo9512366.mockable.io/FlipperGet"];
if (!url) {
return;
}
__weak NetworkViewController* weakSelf = self;
[[[NSURLSession sharedSession]
dataTaskWithURL:
[NSURL URLWithString:@"https://demo9512366.mockable.io/FlipperGet"]
dataTaskWithURL:url
completionHandler:^(
NSData* _Nullable data,
NSData* data,
NSURLResponse* _Nullable response,
NSError* _Nullable error) {
if (error || !data) {
if (error) {
[weakSelf showAlertWithMessage:@"Received error in GET API response"];
return;
}
NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:data
options:0
error:&error];
NSLog(@"MSG-GET: %@", dict[@"msg"]);
[weakSelf showAlertWithMessage:@"Received response from GET API"];
if (data == nil) {
[weakSelf
showAlertWithMessage:@"No data received in GET API response"];
} else {
NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:data
options:0
error:&error];
NSLog(@"MSG-GET: %@", dict[@"msg"]);
[weakSelf showAlertWithMessage:@"Received response from GET API"];
}
}] resume];
}

Expand Down
7 changes: 5 additions & 2 deletions iOS/Sample/UserDefaultsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ - (instancetype)initWithCoder:(NSCoder*)aDecoder {
}

- (IBAction)tappedSave:(id)sender {
[self.userDefaults setObject:self.valueTextField.text
forKey:self.keyTextField.text];
NSString* key = self.keyTextField.text;
NSString* value = self.valueTextField.text;
if (key != nil) {
[self.userDefaults setObject:value forKey:key];
}
}

@end

0 comments on commit 7f6d1cf

Please sign in to comment.