From 11d45ef92a24ac828a71bec830d1503e77d355ae Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Mon, 9 May 2016 19:01:25 -0500 Subject: [PATCH] Remove deprecations & outdated compatibility code --- Example/DetailViewController.m | 9 +- .../TTTAttributedLabelTests.m | 19 --- TTTAttributedLabel/TTTAttributedLabel.h | 20 --- TTTAttributedLabel/TTTAttributedLabel.m | 127 ++---------------- 4 files changed, 13 insertions(+), 162 deletions(-) diff --git a/Example/DetailViewController.m b/Example/DetailViewController.m index aa225a2c..d7622848 100644 --- a/Example/DetailViewController.m +++ b/Example/DetailViewController.m @@ -23,9 +23,6 @@ #import "DetailViewController.h" #import "TTTAttributedLabel.h" -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - static CGFloat const kEspressoDescriptionTextFontSize = 17.0f; static inline NSRegularExpression * NameRegularExpression() { @@ -91,8 +88,8 @@ - (void)viewDidLoad { UIFont *f = [UIFont systemFontOfSize:kEspressoDescriptionTextFontSize]; self.attributedLabel.font = f; self.attributedLabel.textColor = [UIColor darkGrayColor]; - self.attributedLabel.lineBreakMode = UILineBreakModeWordWrap; - self.attributedLabel.leading = -100; + self.attributedLabel.lineBreakMode = NSLineBreakByWordWrapping; + self.attributedLabel.lineSpacing = -100; self.attributedLabel.maximumLineHeight = f.lineHeight; self.attributedLabel.minimumLineHeight = f.lineHeight; self.attributedLabel.numberOfLines = 0; @@ -162,5 +159,3 @@ - (void)actionSheet:(UIActionSheet *)actionSheet } @end - -#pragma clang diagnostic pop diff --git a/Example/TTTAttributedLabelTests/TTTAttributedLabelTests.m b/Example/TTTAttributedLabelTests/TTTAttributedLabelTests.m index 9554aae9..12bd847e 100644 --- a/Example/TTTAttributedLabelTests/TTTAttributedLabelTests.m +++ b/Example/TTTAttributedLabelTests/TTTAttributedLabelTests.m @@ -1046,23 +1046,4 @@ - (void)testLinkAccessibility { timeStyle:NSDateFormatterLongStyle]); } -#pragma mark - Deprecated Methods - -- (void)testLeading { - // Deprecated -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - [label setLeading:1.f]; -#pragma clang diagnostic pop - expect(label.lineSpacing).to.equal(1.f); -} - -- (void)testDataDetectorTypes { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - label.dataDetectorTypes = NSTextCheckingTypeLink; - expect(label.dataDetectorTypes).will.equal(NSTextCheckingTypeLink); -#pragma clang diagnostic pop -} - @end diff --git a/TTTAttributedLabel/TTTAttributedLabel.h b/TTTAttributedLabel/TTTAttributedLabel.h index da1ccb80..320be511 100644 --- a/TTTAttributedLabel/TTTAttributedLabel.h +++ b/TTTAttributedLabel/TTTAttributedLabel.h @@ -127,11 +127,6 @@ IB_DESIGNABLE /// @name Detecting, Accessing, & Styling Links ///-------------------------------------------- -/** - @deprecated Use `enabledTextCheckingTypes` property instead. - */ -@property (nonatomic, assign) NSTextCheckingTypes dataDetectorTypes DEPRECATED_ATTRIBUTE; - /** A bitmask of `NSTextCheckingType` which are used to automatically detect links in the label text. @@ -209,11 +204,6 @@ IB_DESIGNABLE */ @property (nonatomic, assign) IBInspectable CGFloat firstLineIndent; -/** - @deprecated Use `lineSpacing` instead. - */ -@property (nonatomic, assign) IBInspectable CGFloat leading DEPRECATED_ATTRIBUTE; - /** The space in points added between lines within the paragraph. This value is always nonnegative and is 0.0 by default. */ @@ -258,16 +248,6 @@ IB_DESIGNABLE /// @name Accessing Truncation Token Appearance ///-------------------------------------------- -/** - @deprecated Use `attributedTruncationToken` instead. - */ -@property (nonatomic, strong) NSString *truncationTokenString DEPRECATED_ATTRIBUTE; - -/** - @deprecated Use `attributedTruncationToken` instead. - */ -@property (nonatomic, strong) NSDictionary *truncationTokenStringAttributes DEPRECATED_ATTRIBUTE; - /** The attributed string to apply to the truncation token at the end of a truncated line. Overrides `truncationTokenStringAttributes` and `truncationTokenString`. If unspecified, attributes will fallback to `truncationTokenStringAttributes` and `truncationTokenString`. */ diff --git a/TTTAttributedLabel/TTTAttributedLabel.m b/TTTAttributedLabel/TTTAttributedLabel.m index 184972b5..48f63287 100644 --- a/TTTAttributedLabel/TTTAttributedLabel.m +++ b/TTTAttributedLabel/TTTAttributedLabel.m @@ -37,7 +37,6 @@ NSString * const kTTTBackgroundLineWidthAttributeName = @"TTTBackgroundLineWidth"; NSString * const kTTTBackgroundCornerRadiusAttributeName = @"TTTBackgroundCornerRadius"; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 60000 const NSTextAlignment TTTTextAlignmentLeft = NSTextAlignmentLeft; const NSTextAlignment TTTTextAlignmentCenter = NSTextAlignmentCenter; const NSTextAlignment TTTTextAlignmentRight = NSTextAlignmentRight; @@ -53,27 +52,9 @@ typedef NSTextAlignment TTTTextAlignment; typedef NSLineBreakMode TTTLineBreakMode; -#else -const UITextAlignment TTTTextAlignmentLeft = NSTextAlignmentLeft; -const UITextAlignment TTTTextAlignmentCenter = NSTextAlignmentCenter; -const UITextAlignment TTTTextAlignmentRight = NSTextAlignmentRight; -const UITextAlignment TTTTextAlignmentJustified = NSTextAlignmentJustified; -const UITextAlignment TTTTextAlignmentNatural = NSTextAlignmentNatural; - -const UITextAlignment TTTLineBreakByWordWrapping = NSLineBreakByWordWrapping; -const UITextAlignment TTTLineBreakByCharWrapping = NSLineBreakByCharWrapping; -const UITextAlignment TTTLineBreakByClipping = NSLineBreakByClipping; -const UITextAlignment TTTLineBreakByTruncatingHead = NSLineBreakByTruncatingHead; -const UITextAlignment TTTLineBreakByTruncatingMiddle = NSLineBreakByTruncatingMiddle; -const UITextAlignment TTTLineBreakByTruncatingTail = NSLineBreakByTruncatingTail; - -typedef UITextAlignment TTTTextAlignment; -typedef UILineBreakMode TTTLineBreakMode; -#endif static inline CTTextAlignment CTTextAlignmentFromTTTTextAlignment(TTTTextAlignment alignment) { -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 60000 switch (alignment) { #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 90000 case NSTextAlignmentLeft: return kCTTextAlignmentLeft; @@ -87,18 +68,9 @@ static inline CTTextAlignment CTTextAlignmentFromTTTTextAlignment(TTTTextAlignme default: return kCTNaturalTextAlignment; #endif } -#else - switch (alignment) { - case UITextAlignmentLeft: return kCTLeftTextAlignment; - case UITextAlignmentCenter: return kCTCenterTextAlignment; - case UITextAlignmentRight: return kCTRightTextAlignment; - default: return kCTNaturalTextAlignment; - } -#endif } static inline CTLineBreakMode CTLineBreakModeFromTTTLineBreakMode(TTTLineBreakMode lineBreakMode) { -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 60000 switch (lineBreakMode) { case NSLineBreakByWordWrapping: return kCTLineBreakByWordWrapping; case NSLineBreakByCharWrapping: return kCTLineBreakByCharWrapping; @@ -108,28 +80,8 @@ static inline CTLineBreakMode CTLineBreakModeFromTTTLineBreakMode(TTTLineBreakMo case NSLineBreakByTruncatingMiddle: return kCTLineBreakByTruncatingMiddle; default: return 0; } -#else - return CTLineBreakModeFromUILineBreakMode(lineBreakMode); -#endif } -#if __IPHONE_OS_VERSION_MAX_ALLOWED < 60000 -static inline CTLineBreakMode CTLineBreakModeFromUILineBreakMode(UILineBreakMode lineBreakMode) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - switch (lineBreakMode) { - case UILineBreakModeWordWrap: return kCTLineBreakByWordWrapping; - case UILineBreakModeCharacterWrap: return kCTLineBreakByCharWrapping; - case UILineBreakModeClip: return kCTLineBreakByClipping; - case UILineBreakModeHeadTruncation: return kCTLineBreakByTruncatingHead; - case UILineBreakModeTailTruncation: return kCTLineBreakByTruncatingTail; - case UILineBreakModeMiddleTruncation: return kCTLineBreakByTruncatingMiddle; - default: return 0; - } -#pragma clang diagnostic pop -} -#endif - static inline CGFLOAT_TYPE CGFloat_ceil(CGFLOAT_TYPE cgfloat) { #if CGFLOAT_IS_DOUBLE return ceil(cgfloat); @@ -316,8 +268,6 @@ static inline CGSize CTFramesetterSuggestFrameSizeForAttributedStringWithConstra return CGSizeMake(CGFloat_ceil(suggestedSize.width), CGFloat_ceil(suggestedSize.height)); } -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 - @interface TTTAccessibilityElement : UIAccessibilityElement @property (nonatomic, weak) UIView *superview; @property (nonatomic, assign) CGRect boundingRect; @@ -331,8 +281,6 @@ - (CGRect)accessibilityFrame { @end -#endif - @interface TTTAttributedLabel () @property (readwrite, nonatomic, copy) NSAttributedString *inactiveAttributedText; @property (readwrite, nonatomic, copy) NSAttributedString *renderedAttributedText; @@ -354,8 +302,6 @@ @implementation TTTAttributedLabel { @dynamic text; @synthesize attributedText = _attributedText; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 - #ifndef kCFCoreFoundationVersionNumber_iOS_7_0 #define kCFCoreFoundationVersionNumber_iOS_7_0 847.2 #endif @@ -384,7 +330,6 @@ + (void)load { } }); } -#endif - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; @@ -484,11 +429,9 @@ - (void)setAttributedText:(NSAttributedString *)text { [self setNeedsFramesetter]; [self setNeedsDisplay]; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 60000 if ([self respondsToSelector:@selector(invalidateIntrinsicContentSize)]) { [self invalidateIntrinsicContentSize]; } -#endif [super setText:[self.attributedText string]]; } @@ -563,24 +506,8 @@ - (void)setHighlightFramesetter:(CTFramesetterRef)highlightFramesetter { _highlightFramesetter = highlightFramesetter; } -- (CGFloat)leading { - return self.lineSpacing; -} - -- (void)setLeading:(CGFloat)leading { - self.lineSpacing = leading; -} - #pragma mark - -- (NSTextCheckingTypes)dataDetectorTypes { - return self.enabledTextCheckingTypes; -} - -- (void)setDataDetectorTypes:(NSTextCheckingTypes)dataDetectorTypes { - self.enabledTextCheckingTypes = dataDetectorTypes; -} - - (void)setEnabledTextCheckingTypes:(NSTextCheckingTypes)enabledTextCheckingTypes { if (self.enabledTextCheckingTypes == enabledTextCheckingTypes) { return; @@ -838,7 +765,6 @@ - (CFIndex)characterIndexAtPoint:(CGPoint)p { return idx; } -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 - (CGRect)boundingRectForCharacterRange:(NSRange)range { NSMutableAttributedString *mutableAttributedString = [self.attributedText mutableCopy]; @@ -855,7 +781,6 @@ - (CGRect)boundingRectForCharacterRange:(NSRange)range { return [layoutManager boundingRectForGlyphRange:glyphRange inTextContainer:textContainer]; } -#endif - (void)drawFramesetter:(CTFramesetterRef)framesetter attributedString:(NSAttributedString *)attributedString @@ -917,24 +842,15 @@ - (void)drawFramesetter:(CTFramesetterRef)framesetter break; } -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" NSAttributedString *attributedTruncationString = self.attributedTruncationToken; if (!attributedTruncationString) { - NSString *truncationTokenString = self.truncationTokenString; - if (!truncationTokenString) { - truncationTokenString = @"\u2026"; // Unicode Character 'HORIZONTAL ELLIPSIS' (U+2026) - } + NSString *truncationTokenString = @"\u2026"; // Unicode Character 'HORIZONTAL ELLIPSIS' (U+2026) - NSDictionary *truncationTokenStringAttributes = self.truncationTokenStringAttributes; - if (!truncationTokenStringAttributes) { - truncationTokenStringAttributes = [attributedString attributesAtIndex:(NSUInteger)truncationAttributePosition effectiveRange:NULL]; - } + NSDictionary *truncationTokenStringAttributes = truncationTokenStringAttributes = [attributedString attributesAtIndex:(NSUInteger)truncationAttributePosition effectiveRange:NULL]; attributedTruncationString = [[NSAttributedString alloc] initWithString:truncationTokenString attributes:truncationTokenStringAttributes]; } CTLineRef truncationToken = CTLineCreateWithAttributedString((__bridge CFAttributedStringRef)attributedTruncationString); -#pragma clang diagnostic pop // Append truncationToken to the string // because if string isn't too long, CT won't add the truncationToken on its own. @@ -1161,11 +1077,7 @@ - (void)setText:(id)text { self.linkModels = [NSArray array]; if (text && self.attributedText && self.enabledTextCheckingTypes) { -#if __IPHONE_OS_VERSION_MIN_REQUIRED < 50000 - __unsafe_unretained __typeof(self)weakSelf = self; -#else __weak __typeof(self)weakSelf = self; -#endif dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ __strong __typeof(weakSelf)strongSelf = weakSelf; @@ -1183,16 +1095,12 @@ - (void)setText:(id)text { }); } -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 - if (&NSLinkAttributeName) { - [self.attributedText enumerateAttribute:NSLinkAttributeName inRange:NSMakeRange(0, self.attributedText.length) options:0 usingBlock:^(id value, __unused NSRange range, __unused BOOL *stop) { - if (value) { - NSURL *URL = [value isKindOfClass:[NSString class]] ? [NSURL URLWithString:value] : value; - [self addLinkToURL:URL withRange:range]; - } - }]; - } -#endif + [self.attributedText enumerateAttribute:NSLinkAttributeName inRange:NSMakeRange(0, self.attributedText.length) options:0 usingBlock:^(id value, __unused NSRange range, __unused BOOL *stop) { + if (value) { + NSURL *URL = [value isKindOfClass:[NSString class]] ? [NSURL URLWithString:value] : value; + [self addLinkToURL:URL withRange:range]; + } + }]; } - (void)setText:(id)text @@ -1334,11 +1242,9 @@ - (void)drawTextInRect:(CGRect)rect { [self setNeedsFramesetter]; [self setNeedsDisplay]; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 60000 if ([self respondsToSelector:@selector(invalidateIntrinsicContentSize)]) { [self invalidateIntrinsicContentSize]; } -#endif // Use infinite width to find the max width, which will be compared to availableWidth if needed. CGSize maxSize = (self.numberOfLines > 1) ? CGSizeMake(TTTFLOAT_MAX, TTTFLOAT_MAX) : CGSizeZero; @@ -1412,8 +1318,6 @@ - (void)drawTextInRect:(CGRect)rect { #pragma mark - UIAccessibilityElement -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 - - (BOOL)isAccessibilityElement { return NO; } @@ -1477,7 +1381,6 @@ - (NSArray *)accessibilityElements { return _accessibilityElements; } -#endif #pragma mark - UIView @@ -1506,7 +1409,6 @@ - (CGSize)intrinsicContentSize { return [self sizeThatFits:[super intrinsicContentSize]]; } -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 - (void)tintColorDidChange { if (!self.inactiveLinkAttributes || [self.inactiveLinkAttributes count] == 0) { return; @@ -1536,7 +1438,6 @@ - (void)tintColorDidChange { [self setNeedsDisplay]; } -#endif - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event @@ -1766,10 +1667,7 @@ - (void)encodeWithCoder:(NSCoder *)coder { [coder encodeUIEdgeInsets:self.textInsets forKey:NSStringFromSelector(@selector(textInsets))]; [coder encodeInteger:self.verticalAlignment forKey:NSStringFromSelector(@selector(verticalAlignment))]; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - [coder encodeObject:self.truncationTokenString forKey:NSStringFromSelector(@selector(truncationTokenString))]; -#pragma clang diagnostic pop + [coder encodeObject:self.attributedTruncationToken forKey:NSStringFromSelector(@selector(attributedTruncationToken))]; [coder encodeObject:NSStringFromUIEdgeInsets(self.linkBackgroundEdgeInset) forKey:NSStringFromSelector(@selector(linkBackgroundEdgeInset))]; [coder encodeObject:self.attributedText forKey:NSStringFromSelector(@selector(attributedText))]; @@ -1859,12 +1757,9 @@ - (id)initWithCoder:(NSCoder *)coder { self.verticalAlignment = [coder decodeIntegerForKey:NSStringFromSelector(@selector(verticalAlignment))]; } -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - if ([coder containsValueForKey:NSStringFromSelector(@selector(truncationTokenString))]) { - self.truncationTokenString = [coder decodeObjectForKey:NSStringFromSelector(@selector(truncationTokenString))]; + if ([coder containsValueForKey:NSStringFromSelector(@selector(attributedTruncationToken))]) { + self.attributedTruncationToken = [coder decodeObjectForKey:NSStringFromSelector(@selector(attributedTruncationToken))]; } -#pragma clang diagnostic pop if ([coder containsValueForKey:NSStringFromSelector(@selector(linkBackgroundEdgeInset))]) { self.linkBackgroundEdgeInset = UIEdgeInsetsFromString([coder decodeObjectForKey:NSStringFromSelector(@selector(linkBackgroundEdgeInset))]);