Skip to content

Commit 77e79d6

Browse files
author
Ian Gordon
committed
Eliminate repeated weak references in MDCThumbTrack
Summary: Enabled warning to check for repeated use of weak variables. Updated code to eliminate repeated weak variable references. Please sanity check my changes for retain cycles. Reviewers: featherless, #material_components_ios_owners, randallli Reviewed By: featherless, #material_components_ios_owners, randallli Projects: #material_components_ios Differential Revision: http://codereview.cc/D96
1 parent 55cca10 commit 77e79d6

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

components/Switch/Switch.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@
423423
CLANG_WARN_EMPTY_BODY = YES;
424424
CLANG_WARN_ENUM_CONVERSION = YES;
425425
CLANG_WARN_INT_CONVERSION = YES;
426+
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES;
426427
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
427428
CLANG_WARN_UNREACHABLE_CODE = YES;
428429
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -467,6 +468,7 @@
467468
CLANG_WARN_EMPTY_BODY = YES;
468469
CLANG_WARN_ENUM_CONVERSION = YES;
469470
CLANG_WARN_INT_CONVERSION = YES;
471+
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES;
470472
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
471473
CLANG_WARN_UNREACHABLE_CODE = YES;
472474
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -499,6 +501,7 @@
499501
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
500502
PRODUCT_BUNDLE_IDENTIFIER = com.google.Switch;
501503
PRODUCT_NAME = "$(TARGET_NAME)";
504+
WARNING_CFLAGS = "";
502505
};
503506
name = Debug;
504507
};
@@ -510,6 +513,7 @@
510513
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
511514
PRODUCT_BUNDLE_IDENTIFIER = com.google.Switch;
512515
PRODUCT_NAME = "$(TARGET_NAME)";
516+
WARNING_CFLAGS = "";
513517
};
514518
name = Release;
515519
};

components/private/ThumbTrack/src/MDCThumbTrack.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,19 +611,21 @@ - (void)setValueFromThumbPosition:(CGPoint)position isTap:(BOOL)isTap {
611611
} else {
612612
value = [self valueForThumbPosition:position];
613613
}
614-
__weak MDCThumbTrack *weakSelf = self;
615-
if ([_delegate respondsToSelector:@selector(thumbTrack:willAnimateToValue:)]) {
616-
[_delegate thumbTrack:self willAnimateToValue:value];
614+
__strong typeof(_delegate) strongDelegate = _delegate;
615+
if ([strongDelegate respondsToSelector:@selector(thumbTrack:willAnimateToValue:)]) {
616+
[strongDelegate thumbTrack:self willAnimateToValue:value];
617617
}
618+
__weak typeof(self) weakSelf = self;
618619
[self setValue:value
619620
animated:YES
620621
userGenerated:YES
621622
completion:^{
622-
MDCThumbTrack *strongSelf = weakSelf;
623+
__strong typeof(weakSelf) strongSelf = weakSelf;
624+
__strong typeof(strongSelf->_delegate) strongDelegate = strongSelf->_delegate;
623625
[strongSelf sendDiscreteChangeAction];
624-
if (strongSelf && [strongSelf->_delegate
626+
if (strongSelf && [strongDelegate
625627
respondsToSelector:@selector(thumbTrack:didAnimateToValue:)]) {
626-
[strongSelf->_delegate thumbTrack:weakSelf didAnimateToValue:value];
628+
[strongDelegate thumbTrack:strongSelf didAnimateToValue:value];
627629
}
628630
}];
629631
}

0 commit comments

Comments
 (0)