Address Xcode warnings about unguarded availability and implicit self retains (#1207)

This commit is contained in:
Adlai Holler
2018-11-01 19:40:16 -07:00
committed by GitHub
parent fde47a5e28
commit 0380b270bb
9 changed files with 40 additions and 40 deletions

View File

@@ -570,11 +570,11 @@ static std::atomic_bool _useMainThreadDelegateCallbacks(true);
// it and try again.
{
ASLockScopeSelf();
url = _URL;
url = self->_URL;
}
downloadIdentifier = [_downloader downloadImageWithURL:url
downloadIdentifier = [self->_downloader downloadImageWithURL:url
callbackQueue:[self callbackQueue]
downloadProgress:NULL
completion:^(id <ASImageContainerProtocol> _Nullable imageContainer, NSError * _Nullable error, id _Nullable downloadIdentifier, id _Nullable userInfo) {
@@ -586,9 +586,9 @@ static std::atomic_bool _useMainThreadDelegateCallbacks(true);
{
ASLockScopeSelf();
if (ASObjectIsEqual(_URL, url)) {
if (ASObjectIsEqual(self->_URL, url)) {
// The download we kicked off is correct, no need to do any more work.
_downloadIdentifier = downloadIdentifier;
self->_downloadIdentifier = downloadIdentifier;
} else {
// The URL changed since we kicked off our download task. This shouldn't happen often so we'll pay the cost and
// cancel that request and kick off a new one.
@@ -599,7 +599,7 @@ static std::atomic_bool _useMainThreadDelegateCallbacks(true);
if (cancelAndReattempt) {
if (downloadIdentifier != nil) {
as_log_verbose(ASImageLoadingLog(), "Canceling image download no resume for %@ id: %@", self, downloadIdentifier);
[_downloader cancelImageDownloadForIdentifier:downloadIdentifier];
[self->_downloader cancelImageDownloadForIdentifier:downloadIdentifier];
}
[self _downloadImageWithCompletion:finished];
return;
@@ -631,11 +631,11 @@ static std::atomic_bool _useMainThreadDelegateCallbacks(true);
ASLockScopeSelf();
// Bail out if not the same URL anymore
if (!ASObjectIsEqual(URL, _URL)) {
if (!ASObjectIsEqual(URL, self->_URL)) {
return;
}
if (_shouldCacheImage) {
if (self->_shouldCacheImage) {
[self _locked__setImage:[UIImage imageNamed:URL.path.lastPathComponent]];
} else {
// First try to load the path directly, for efficiency assuming a developer who
@@ -652,10 +652,10 @@ static std::atomic_bool _useMainThreadDelegateCallbacks(true);
// If the file may be an animated gif and then created an animated image.
id<ASAnimatedImageProtocol> animatedImage = nil;
if (_downloaderFlags.downloaderImplementsAnimatedImage) {
if (self->_downloaderFlags.downloaderImplementsAnimatedImage) {
let data = [[NSData alloc] initWithContentsOfURL:URL];
if (data != nil) {
animatedImage = [_downloader animatedImageWithData:data];
animatedImage = [self->_downloader animatedImageWithData:data];
if ([animatedImage respondsToSelector:@selector(isDataSupported:)] && [animatedImage isDataSupported:data] == NO) {
animatedImage = nil;
@@ -670,15 +670,15 @@ static std::atomic_bool _useMainThreadDelegateCallbacks(true);
}
}
_imageLoaded = YES;
self->_imageLoaded = YES;
[self _setCurrentImageQuality:1.0];
if (_delegateFlags.delegateDidLoadImageWithInfo) {
if (self->_delegateFlags.delegateDidLoadImageWithInfo) {
ASUnlockScope(self);
let info = [[ASNetworkImageLoadInfo alloc] initWithURL:URL sourceType:ASNetworkImageSourceFileURL downloadIdentifier:nil userInfo:nil];
[delegate imageNode:self didLoadImage:self.image info:info];
} else if (_delegateFlags.delegateDidLoadImage) {
} else if (self->_delegateFlags.delegateDidLoadImage) {
ASUnlockScope(self);
[delegate imageNode:self didLoadImage:self.image];
}
@@ -729,17 +729,17 @@ static std::atomic_bool _useMainThreadDelegateCallbacks(true);
void (^calloutBlock)(ASNetworkImageNode *inst);
if (newImage) {
if (_delegateFlags.delegateDidLoadImageWithInfo) {
if (self->_delegateFlags.delegateDidLoadImageWithInfo) {
calloutBlock = ^(ASNetworkImageNode *strongSelf) {
let info = [[ASNetworkImageLoadInfo alloc] initWithURL:URL sourceType:imageSource downloadIdentifier:downloadIdentifier userInfo:userInfo];
[delegate imageNode:strongSelf didLoadImage:newImage info:info];
};
} else if (_delegateFlags.delegateDidLoadImage) {
} else if (self->_delegateFlags.delegateDidLoadImage) {
calloutBlock = ^(ASNetworkImageNode *strongSelf) {
[delegate imageNode:strongSelf didLoadImage:newImage];
};
}
} else if (error && _delegateFlags.delegateDidFailWithError) {
} else if (error && self->_delegateFlags.delegateDidFailWithError) {
calloutBlock = ^(ASNetworkImageNode *strongSelf) {
[delegate imageNode:strongSelf didFailWithError:error];
};
@@ -768,11 +768,11 @@ static std::atomic_bool _useMainThreadDelegateCallbacks(true);
ASImageCacherCompletion completion = ^(id <ASImageContainerProtocol> imageContainer) {
// If the cache sentinel changed, that means this request was cancelled.
if (ASLockedSelf(_cacheSentinel != cacheSentinel)) {
if (ASLockedSelf(self->_cacheSentinel != cacheSentinel)) {
return;
}
if ([imageContainer asdk_image] == nil && _downloader != nil) {
if ([imageContainer asdk_image] == nil && self->_downloader != nil) {
[self _downloadImageWithCompletion:^(id<ASImageContainerProtocol> imageContainer, NSError *error, id downloadIdentifier, id userInfo) {
finished(imageContainer, error, downloadIdentifier, ASNetworkImageSourceDownload, userInfo);
}];

View File

@@ -607,7 +607,7 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
return;
}
for (NSString *attributeName in _linkAttributeNames) {
for (NSString *attributeName in self->_linkAttributeNames) {
NSRange range;
id value = [attributedString attribute:attributeName atIndex:characterIndex longestEffectiveRange:&range inRange:clampedRange];
NSString *name = attributeName;
@@ -619,8 +619,8 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
// If highlighting, check with delegate first. If not implemented, assume YES.
if (highlighting
&& [_delegate respondsToSelector:@selector(textNode:shouldHighlightLinkAttribute:value:atPoint:)]
&& ![_delegate textNode:self shouldHighlightLinkAttribute:name value:value atPoint:point]) {
&& [self->_delegate respondsToSelector:@selector(textNode:shouldHighlightLinkAttribute:value:atPoint:)]
&& ![self->_delegate textNode:self shouldHighlightLinkAttribute:name value:value atPoint:point]) {
value = nil;
name = nil;
}

View File

@@ -52,16 +52,16 @@
{
dispatch_block_t mainThread = ^{
do {
ASDN::MutexLocker l(_serialQueueLock);
ASDN::MutexLocker l(self->_serialQueueLock);
dispatch_block_t block;
if (_blocks.count > 0) {
if (self->_blocks.count > 0) {
block = _blocks[0];
[_blocks removeObjectAtIndex:0];
[self->_blocks removeObjectAtIndex:0];
} else {
break;
}
{
ASDN::MutexUnlocker u(_serialQueueLock);
ASDN::MutexUnlocker u(self->_serialQueueLock);
block();
}
} while (true);

View File

@@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
OS_UNFAIR_LOCK_AVAILABILITY
typedef struct {
os_unfair_lock _lock;
os_unfair_lock _lock OS_UNFAIR_LOCK_AVAILABILITY;
_Atomic(pthread_t) _thread; // Write-protected by lock
int _count; // Protected by lock
} ASRecursiveUnfairLock;

View File

@@ -61,11 +61,11 @@ typedef struct ASPrimitiveTraitCollection {
UIUserInterfaceSizeClass verticalSizeClass;
CGFloat displayScale;
UIDisplayGamut displayGamut;
UIDisplayGamut displayGamut API_AVAILABLE(ios(10.0));
UIUserInterfaceIdiom userInterfaceIdiom;
UIForceTouchCapability forceTouchCapability;
UITraitEnvironmentLayoutDirection layoutDirection;
UITraitEnvironmentLayoutDirection layoutDirection API_AVAILABLE(ios(10.0));
#if TARGET_OS_TV
UIUserInterfaceStyle userInterfaceStyle;
#endif
@@ -168,11 +168,11 @@ AS_SUBCLASSING_RESTRICTED
@property (nonatomic, readonly) UIUserInterfaceSizeClass verticalSizeClass;
@property (nonatomic, readonly) CGFloat displayScale;
@property (nonatomic, readonly) UIDisplayGamut displayGamut;
@property (nonatomic, readonly) UIDisplayGamut displayGamut API_AVAILABLE(ios(10.0));
@property (nonatomic, readonly) UIUserInterfaceIdiom userInterfaceIdiom;
@property (nonatomic, readonly) UIForceTouchCapability forceTouchCapability;
@property (nonatomic, readonly) UITraitEnvironmentLayoutDirection layoutDirection;
@property (nonatomic, readonly) UITraitEnvironmentLayoutDirection layoutDirection API_AVAILABLE(ios(10.0));
#if TARGET_OS_TV
@property (nonatomic, readonly) UIUserInterfaceStyle userInterfaceStyle;
#endif

View File

@@ -835,7 +835,7 @@ dispatch_semaphore_signal(_lock);
}
int i = 0;
if (type != kCTLineTruncationStart) { // Middle or End/Tail wants text preceding truncated content.
i = removedLines.count - 1;
i = (int)removedLines.count - 1;
while (atLeastOneLine < truncatedWidth && i >= 0) {
if (lastLineText.length > 0 && [lastLineText.string characterAtIndex:lastLineText.string.length - 1] == '\n') { // Explicit newlines are always "long enough".
[lastLineText deleteCharactersInRange:NSMakeRange(lastLineText.string.length - 1, 1)];

View File

@@ -183,8 +183,8 @@
// check to see if we may need to shrink for any of these things
BOOL longestWordFits = [longestWordNeedingResize length] ? NO : YES;
BOOL maxLinesFits = _attributes.maximumNumberOfLines > 0 ? NO : YES;
BOOL heightFits = isinf(_constrainedSize.height) ? YES : NO;
BOOL maxLinesFits = self->_attributes.maximumNumberOfLines > 0 ? NO : YES;
BOOL heightFits = isinf(self->_constrainedSize.height) ? YES : NO;
CGSize longestWordSize = CGSizeZero;
if (longestWordFits == NO) {
@@ -204,7 +204,7 @@
if (longestWordFits == NO) {
// we need to check the longest word to make sure it fits
longestWordFits = std::ceil((longestWordSize.width * adjustedScale) <= _constrainedSize.width);
longestWordFits = std::ceil((longestWordSize.width * adjustedScale) <= self->_constrainedSize.width);
}
// if the longest word fits, go ahead and check max line and height. If it didn't fit continue to the next scale factor
@@ -216,14 +216,14 @@
// check to see if this scaled string fit in the max lines
if (maxLinesFits == NO) {
maxLinesFits = ([self lineCountForString:scaledString] <= _attributes.maximumNumberOfLines);
maxLinesFits = ([self lineCountForString:scaledString] <= self->_attributes.maximumNumberOfLines);
}
// if max lines still doesn't fit, continue without checking that we fit in the constrained height
if (maxLinesFits == YES && heightFits == NO) {
// max lines fit so make sure that we fit in the constrained height.
CGSize stringSize = [self boundingBoxForString:scaledString];
heightFits = (stringSize.height <= _constrainedSize.height);
heightFits = (stringSize.height <= self->_constrainedSize.height);
}
}
}

View File

@@ -128,7 +128,7 @@ static NSCharacterSet *_defaultAvoidTruncationCharacterSet()
// apply the string scale before truncating or else we may truncate the string after we've done the work to shrink it.
[[self context] performBlockWithLockedTextKitComponents:^(NSLayoutManager *layoutManager, NSTextStorage *textStorage, NSTextContainer *textContainer) {
NSMutableAttributedString *scaledString = [[NSMutableAttributedString alloc] initWithAttributedString:textStorage];
[ASTextKitFontSizeAdjuster adjustFontSizeForAttributeString:scaledString withScaleFactor:_currentScaleFactor];
[ASTextKitFontSizeAdjuster adjustFontSizeForAttributeString:scaledString withScaleFactor:self->_currentScaleFactor];
scaledTextStorage = [[NSTextStorage alloc] initWithAttributedString:scaledString];
[textStorage removeLayoutManager:layoutManager];
@@ -217,7 +217,7 @@ static NSCharacterSet *_defaultAvoidTruncationCharacterSet()
if (isScaled) {
// if we are going to scale the text, swap out the non-scaled text for the scaled version.
NSMutableAttributedString *scaledString = [[NSMutableAttributedString alloc] initWithAttributedString:textStorage];
[ASTextKitFontSizeAdjuster adjustFontSizeForAttributeString:scaledString withScaleFactor:_currentScaleFactor];
[ASTextKitFontSizeAdjuster adjustFontSizeForAttributeString:scaledString withScaleFactor:self->_currentScaleFactor];
scaledTextStorage = [[NSTextStorage alloc] initWithAttributedString:scaledString];
[textStorage removeLayoutManager:layoutManager];

View File

@@ -157,7 +157,7 @@
actualGlyphRange:NULL];
// Check if text is truncated, and if so apply our truncation string
if (visibleCharacterRange.length < originalStringLength && _truncationAttributedString.length > 0) {
if (visibleCharacterRange.length < originalStringLength && self->_truncationAttributedString.length > 0) {
NSInteger firstCharacterIndexToReplace = [self _calculateCharacterIndexBeforeTruncationMessage:layoutManager
textStorage:textStorage
textContainer:textContainer];
@@ -171,10 +171,10 @@
textStorage.length - firstCharacterIndexToReplace);
// Replace the end of the visible message with the truncation string
[textStorage replaceCharactersInRange:truncationReplacementRange
withAttributedString:_truncationAttributedString];
withAttributedString:self->_truncationAttributedString];
}
_visibleRanges = { visibleCharacterRange };
self->_visibleRanges = { visibleCharacterRange };
}];
}