diff --git a/.travis.yml b/.travis.yml index 790372a3..9a7228a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: objective-c -osx_image: xcode8 +osx_image: xcode9 before_install: - gem install scan - scan --version install: true script: -- scan -p "ActiveLabel.xcodeproj" -s "ActiveLabel" \ No newline at end of file +- scan -p "ActiveLabel.xcodeproj" -s "ActiveLabel" diff --git a/ActiveLabel.xcodeproj/project.pbxproj b/ActiveLabel.xcodeproj/project.pbxproj index 78bdd57a..22627713 100644 --- a/ActiveLabel.xcodeproj/project.pbxproj +++ b/ActiveLabel.xcodeproj/project.pbxproj @@ -235,12 +235,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = Optonaut; TargetAttributes = { 8F0249A11B9989B1005D8035 = { CreatedOnToolsVersion = 7.0; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; 8F0249AB1B9989B1005D8035 = { CreatedOnToolsVersion = 7.0; @@ -248,6 +248,7 @@ }; 8F0249BF1B998A66005D8035 = { CreatedOnToolsVersion = 7.0; + LastSwiftMigration = 0900; }; }; }; @@ -371,14 +372,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -407,6 +414,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -421,14 +429,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -450,6 +464,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -474,7 +489,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -494,7 +510,8 @@ PRODUCT_BUNDLE_IDENTIFIER = optonaut.ActiveLabel; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -505,7 +522,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = optonaut.ActiveLabelTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -516,7 +533,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = optonaut.ActiveLabelTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -530,7 +547,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = optonaut.ActiveLabelDemo; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -544,7 +562,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = optonaut.ActiveLabelDemo; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/ActiveLabel.xcodeproj/xcshareddata/xcschemes/ActiveLabel.xcscheme b/ActiveLabel.xcodeproj/xcshareddata/xcschemes/ActiveLabel.xcscheme index b5d72fd3..0185d6ea 100644 --- a/ActiveLabel.xcodeproj/xcshareddata/xcschemes/ActiveLabel.xcscheme +++ b/ActiveLabel.xcodeproj/xcshareddata/xcschemes/ActiveLabel.xcscheme @@ -1,6 +1,6 @@ ([String : Any]) +public typealias ConfigureLinkAttribute = (ActiveType, [NSAttributedStringKey : Any], Bool) -> ([NSAttributedStringKey : Any]) typealias ElementTuple = (range: NSRange, element: ActiveElement, type: ActiveType) @IBDesignable open class ActiveLabel: UILabel { @@ -60,7 +60,7 @@ typealias ElementTuple = (range: NSRange, element: ActiveElement, type: ActiveTy @IBInspectable public var highlightFontName: String? = nil { didSet { updateTextStorage(parseText: false) } } - @IBInspectable public var highlightFontSize: CGFloat? = nil { + public var highlightFontSize: CGFloat? = nil { didSet { updateTextStorage(parseText: false) } } @@ -306,23 +306,23 @@ typealias ElementTuple = (range: NSRange, element: ActiveElement, type: ActiveTy var range = NSRange(location: 0, length: 0) var attributes = mutAttrString.attributes(at: 0, effectiveRange: &range) - attributes[NSFontAttributeName] = font! - attributes[NSForegroundColorAttributeName] = textColor + attributes[NSAttributedStringKey.font] = font! + attributes[NSAttributedStringKey.foregroundColor] = textColor mutAttrString.addAttributes(attributes, range: range) - attributes[NSForegroundColorAttributeName] = mentionColor + attributes[NSAttributedStringKey.foregroundColor] = mentionColor for (type, elements) in activeElements { switch type { - case .mention: attributes[NSForegroundColorAttributeName] = mentionColor - case .hashtag: attributes[NSForegroundColorAttributeName] = hashtagColor - case .url: attributes[NSForegroundColorAttributeName] = URLColor - case .custom: attributes[NSForegroundColorAttributeName] = customColor[type] ?? defaultCustomColor + case .mention: attributes[NSAttributedStringKey.foregroundColor] = mentionColor + case .hashtag: attributes[NSAttributedStringKey.foregroundColor] = hashtagColor + case .url: attributes[NSAttributedStringKey.foregroundColor] = URLColor + case .custom: attributes[NSAttributedStringKey.foregroundColor] = customColor[type] ?? defaultCustomColor } if let highlightFont = hightlightFont { - attributes[NSFontAttributeName] = highlightFont + attributes[NSAttributedStringKey.font] = highlightFont } if let configureLinkAttribute = configureLinkAttribute { @@ -373,12 +373,12 @@ typealias ElementTuple = (range: NSRange, element: ActiveElement, type: ActiveTy var range = NSRange(location: 0, length: 0) var attributes = mutAttrString.attributes(at: 0, effectiveRange: &range) - let paragraphStyle = attributes[NSParagraphStyleAttributeName] as? NSMutableParagraphStyle ?? NSMutableParagraphStyle() + let paragraphStyle = attributes[NSAttributedStringKey.paragraphStyle] as? NSMutableParagraphStyle ?? NSMutableParagraphStyle() paragraphStyle.lineBreakMode = NSLineBreakMode.byWordWrapping paragraphStyle.alignment = textAlignment paragraphStyle.lineSpacing = lineSpacing paragraphStyle.minimumLineHeight = minimumLineHeight > 0 ? minimumLineHeight: self.font.pointSize * 1.14 - attributes[NSParagraphStyleAttributeName] = paragraphStyle + attributes[NSAttributedStringKey.paragraphStyle] = paragraphStyle mutAttrString.setAttributes(attributes, range: range) return mutAttrString @@ -402,7 +402,7 @@ typealias ElementTuple = (range: NSRange, element: ActiveElement, type: ActiveTy let possibleSelectedColor = customSelectedColor[selectedElement.type] ?? customColor[selectedElement.type] selectedColor = possibleSelectedColor ?? defaultCustomColor } - attributes[NSForegroundColorAttributeName] = selectedColor + attributes[NSAttributedStringKey.foregroundColor] = selectedColor } else { let unselectedColor: UIColor switch type { @@ -411,11 +411,11 @@ typealias ElementTuple = (range: NSRange, element: ActiveElement, type: ActiveTy case .url: unselectedColor = URLColor case .custom: unselectedColor = customColor[selectedElement.type] ?? defaultCustomColor } - attributes[NSForegroundColorAttributeName] = unselectedColor + attributes[NSAttributedStringKey.foregroundColor] = unselectedColor } if let highlightFont = hightlightFont { - attributes[NSFontAttributeName] = highlightFont + attributes[NSAttributedStringKey.font] = highlightFont } if let configureLinkAttribute = configureLinkAttribute { diff --git a/ActiveLabel/StringTrimExtension.swift b/ActiveLabel/StringTrimExtension.swift index 9bf3161c..9da442e9 100644 --- a/ActiveLabel/StringTrimExtension.swift +++ b/ActiveLabel/StringTrimExtension.swift @@ -11,6 +11,6 @@ import Foundation extension String { func trim(to maximumCharacters: Int) -> String { - return substring(to: index(startIndex, offsetBy: maximumCharacters)) + "..." + return "\(self[..