Skip to content

Commit

Permalink
Fix xcode warnings (#23565)
Browse files Browse the repository at this point in the history
Summary:
As part of #22609, this fixes yet more warnings.
- Adding more __unused to params.
- Refactors `isPackagerRunning` to use NSURLSession.
- Turns off suspicious comma warnings

[iOS] [Fixed] - Xcode Warnings
Pull Request resolved: #23565

Differential Revision: D14161151

Pulled By: cpojer

fbshipit-source-id: 339874711eca718fc6151e84737ccc975225d736
  • Loading branch information
ericlewis authored and facebook-github-bot committed Feb 21, 2019
1 parent 9820c88 commit 468ae23
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 18 deletions.
18 changes: 16 additions & 2 deletions React/Base/RCTBundleURLProvider.m
Expand Up @@ -69,9 +69,23 @@ - (void)resetToDefaults
- (BOOL)isPackagerRunning:(NSString *)host
{
NSURL *url = [serverRootWithHost(host) URLByAppendingPathComponent:@"status"];

NSURLSession *session = [NSURLSession sharedSession];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLResponse *response;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:NULL];
__block NSURLResponse *response;
__block NSData *data;

dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[[session dataTaskWithRequest:request
completionHandler:^(NSData *d,
NSURLResponse *res,
__unused NSError *err) {
data = d;
response = res;
dispatch_semaphore_signal(semaphore);
}] resume];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);

NSString *status = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
return [status isEqualToString:@"packager-status:running"];
}
Expand Down
4 changes: 2 additions & 2 deletions React/DevSupport/RCTDevMenu.m
Expand Up @@ -217,7 +217,7 @@ - (void)addItem:(RCTDevMenuItem *)item
preferredStyle:UIAlertControllerStyleAlert];
__weak typeof(alertController) weakAlertController = alertController;
[alertController addAction:
[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action){
[weakAlertController dismissViewControllerAnimated:YES completion:nil];
}]];
[RCTPresentedViewController() presentViewController:alertController animated:YES completion:NULL];
Expand Down Expand Up @@ -251,7 +251,7 @@ - (void)addItem:(RCTDevMenuItem *)item
preferredStyle:UIAlertControllerStyleAlert];
__weak typeof(alertController) weakAlertController = alertController;
[alertController addAction:
[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action){
[weakAlertController dismissViewControllerAnimated:YES completion:nil];
}]];
[RCTPresentedViewController() presentViewController:alertController animated:YES completion:NULL];
Expand Down
4 changes: 2 additions & 2 deletions React/DevSupport/RCTInspectorDevServerHelper.mm
Expand Up @@ -91,8 +91,8 @@ + (void)attachDebugger:(NSString *)owner

__weak UIViewController *viewCapture = view;
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:
^(NSData *_Nullable data,
NSURLResponse *_Nullable response,
^(__unused NSData *_Nullable data,
__unused NSURLResponse *_Nullable response,
NSError *_Nullable error) {
UIViewController *viewCaptureStrong = viewCapture;
if (error != nullptr && viewCaptureStrong != nullptr) {
Expand Down
10 changes: 5 additions & 5 deletions React/Inspector/RCTInspectorPackagerConnection.m
Expand Up @@ -195,7 +195,7 @@ - (void)sendEvent:(NSString *)name payload:(id)payload
}

// analogous to InspectorPackagerConnection.Connection.onFailure(...)
- (void)webSocket:(RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error
- (void)webSocket:(__unused RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error
{
if (_webSocket) {
[self abort:@"Websocket exception"
Expand All @@ -207,7 +207,7 @@ - (void)webSocket:(RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error
}

// analogous to InspectorPackagerConnection.Connection.onMessage(...)
- (void)webSocket:(RCTSRWebSocket *)webSocket didReceiveMessage:(id)opaqueMessage
- (void)webSocket:(__unused RCTSRWebSocket *)webSocket didReceiveMessage:(id)opaqueMessage
{
// warn but don't die on unrecognized messages
if (![opaqueMessage isKindOfClass:[NSString class]]) {
Expand All @@ -228,9 +228,9 @@ - (void)webSocket:(RCTSRWebSocket *)webSocket didReceiveMessage:(id)opaqueMessag
}

// analogous to InspectorPackagerConnection.Connection.onClosed(...)
- (void)webSocket:(RCTSRWebSocket *)webSocket didCloseWithCode:(NSInteger)code
reason:(NSString *)reason
wasClean:(BOOL)wasClean
- (void)webSocket:(__unused RCTSRWebSocket *)webSocket didCloseWithCode:(__unused NSInteger)code
reason:(__unused NSString *)reason
wasClean:(__unused BOOL)wasClean
{
_webSocket = nil;
[self closeAllConnections];
Expand Down
8 changes: 4 additions & 4 deletions React/Modules/RCTRedBoxExtraDataViewController.m
Expand Up @@ -181,17 +181,17 @@ - (void)viewDidAppear:(BOOL)animated
[_tableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- (NSInteger)tableView:(__unused UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[_extraData objectAtIndex:section] count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- (CGFloat)tableView:(__unused UITableView *)tableView heightForHeaderInSection:(__unused NSInteger)section
{
return 40;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- (UIView *)tableView:(__unused UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [UIView new];
view.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
Expand Down Expand Up @@ -237,7 +237,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSInteger)numberOfSectionsInTableView:(__unused UITableView *)tableView
{
return _extraDataTitle.count;
}
Expand Down
12 changes: 12 additions & 0 deletions React/React.xcodeproj/project.pbxproj
Expand Up @@ -4751,6 +4751,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_WARN_COMMA = NO;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
Expand All @@ -4766,6 +4767,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_WARN_COMMA = NO;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
COPY_PHASE_STRIP = NO;
Expand All @@ -4784,6 +4786,7 @@
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_WARN_COMMA = NO;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
Expand All @@ -4807,6 +4810,7 @@
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_WARN_COMMA = NO;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
COPY_PHASE_STRIP = NO;
Expand All @@ -4830,6 +4834,7 @@
buildSettings = {
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_WARN_COMMA = NO;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
Expand All @@ -4849,6 +4854,7 @@
buildSettings = {
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_WARN_COMMA = NO;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
Expand All @@ -4869,6 +4875,7 @@
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_WARN_COMMA = NO;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
Expand All @@ -4893,6 +4900,7 @@
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_WARN_COMMA = NO;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
COPY_PHASE_STRIP = NO;
Expand All @@ -4916,6 +4924,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_WARN_COMMA = NO;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
Expand All @@ -4932,6 +4941,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_WARN_COMMA = NO;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
COPY_PHASE_STRIP = NO;
Expand Down Expand Up @@ -5200,6 +5210,7 @@
buildSettings = {
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_STATIC_ANALYZER_MODE = deep;
CLANG_WARN_COMMA = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"RCT_DEBUG=1",
Expand All @@ -5225,6 +5236,7 @@
buildSettings = {
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_STATIC_ANALYZER_MODE = deep;
CLANG_WARN_COMMA = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
"RCT_METRO_PORT=${RCT_METRO_PORT}",
Expand Down
2 changes: 1 addition & 1 deletion React/Views/RCTMaskedView.m
Expand Up @@ -24,7 +24,7 @@ - (void)didUpdateReactSubviews
}
}

- (void)displayLayer:(CALayer *)layer
- (void)displayLayer:(__unused CALayer *)layer
{
// RCTView uses displayLayer to do border rendering.
// We don't need to do that in RCTMaskedView, so we
Expand Down
4 changes: 3 additions & 1 deletion React/Views/SafeAreaView/RCTSafeAreaView.m
Expand Up @@ -39,7 +39,9 @@ - (UIEdgeInsets)safeAreaInsetsIfSupportedAndEnabled
{
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
if (self.isSupportedByOS) {
return self.safeAreaInsets;
if (@available(iOS 11.0, *)) {
return self.safeAreaInsets;
}
}
#endif
return self.emulateUnlessSupported ? self.emulatedSafeAreaInsets : UIEdgeInsetsZero;
Expand Down
2 changes: 1 addition & 1 deletion React/Views/ScrollView/RCTScrollView.m
Expand Up @@ -1120,7 +1120,7 @@ - (type)getter \

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
- (void)setContentInsetAdjustmentBehavior:(UIScrollViewContentInsetAdjustmentBehavior)behavior
{
API_AVAILABLE(ios(11.0)){
// `contentInsetAdjustmentBehavior` is available since iOS 11.
if ([_scrollView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
CGPoint contentOffset = _scrollView.contentOffset;
Expand Down

0 comments on commit 468ae23

Please sign in to comment.