diff --git a/.swift-version b/.swift-version index 9f55b2cc..5186d070 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -3.0 +4.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 64c836f4..d41039f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa ## Upcoming release ---------------- +## [Prerelease] 0.8.2 +### Added +- Support for Swift 4 + ## [Prerelease] 0.8.1 ### Added - Support for Swift 3.2 and Xcode 9 diff --git a/Example/ChatExample.xcodeproj/project.pbxproj b/Example/ChatExample.xcodeproj/project.pbxproj index e21d666c..495f2d3d 100644 --- a/Example/ChatExample.xcodeproj/project.pbxproj +++ b/Example/ChatExample.xcodeproj/project.pbxproj @@ -595,7 +595,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -642,7 +642,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -659,7 +659,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.ChatExample; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -675,7 +675,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.ChatExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -688,7 +688,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.hexedbits.ChatExampleTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ChatExample.app/ChatExample"; }; name = Debug; @@ -703,7 +703,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.hexedbits.ChatExampleTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ChatExample.app/ChatExample"; }; name = Release; @@ -716,7 +716,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.hexedbits.ChatExampleUITests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TEST_TARGET_NAME = ChatExample; }; name = Debug; @@ -730,7 +730,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.hexedbits.ChatExampleUITests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TEST_TARGET_NAME = ChatExample; }; name = Release; diff --git a/Example/Sources/ConversationViewController.swift b/Example/Sources/ConversationViewController.swift index 60325a6b..30692f0d 100644 --- a/Example/Sources/ConversationViewController.swift +++ b/Example/Sources/ConversationViewController.swift @@ -45,7 +45,7 @@ class ConversationViewController: MessagesViewController { action: #selector(handleKeyboardButton)) } - func handleKeyboardButton() { + @objc func handleKeyboardButton() { let actionSheetController = UIAlertController(title: "Change Keyboard Style", message: nil, preferredStyle: .actionSheet) let actions = [ @@ -198,14 +198,14 @@ extension ConversationViewController: MessagesDataSource { func cellTopLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? { let name = message.sender.displayName - return NSAttributedString(string: name, attributes: [NSFontAttributeName: UIFont.preferredFont(forTextStyle: .caption1)]) + return NSAttributedString(string: name, attributes: [NSAttributedStringKey.font: UIFont.preferredFont(forTextStyle: .caption1)]) } func cellBottomLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? { let formatter = DateFormatter() formatter.dateStyle = .medium let dateString = formatter.string(from: message.sentDate) - return NSAttributedString(string: dateString, attributes: [NSFontAttributeName: UIFont.preferredFont(forTextStyle: .caption2)]) + return NSAttributedString(string: dateString, attributes: [NSAttributedStringKey.font: UIFont.preferredFont(forTextStyle: .caption2)]) } } diff --git a/Example/Sources/SampleData.swift b/Example/Sources/SampleData.swift index 377eede0..85297a09 100644 --- a/Example/Sources/SampleData.swift +++ b/Example/Sources/SampleData.swift @@ -46,11 +46,11 @@ struct SampleData { let msg9Text = NSString(string: msg9String) let msg9AttributedText = NSMutableAttributedString(string: String(msg9Text)) - msg9AttributedText.addAttribute(NSFontAttributeName, value: UIFont.preferredFont(forTextStyle: .body), range: NSRange(location: 0, length: msg9Text.length)) - msg9AttributedText.addAttributes([NSFontAttributeName: UIFont.monospacedDigitSystemFont(ofSize: UIFont.systemFontSize, weight: UIFontWeightBold)], range: msg9Text.range(of: ".attributedText()")) - msg9AttributedText.addAttributes([NSFontAttributeName: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)], range: msg9Text.range(of: "bold")) - msg9AttributedText.addAttributes([NSFontAttributeName: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)], range: msg9Text.range(of: "italic")) - msg9AttributedText.addAttributes([NSForegroundColorAttributeName: UIColor.red], range: msg9Text.range(of: "colored")) + msg9AttributedText.addAttribute(NSAttributedStringKey.font, value: UIFont.preferredFont(forTextStyle: .body), range: NSRange(location: 0, length: msg9Text.length)) + msg9AttributedText.addAttributes([NSAttributedStringKey.font: UIFont.monospacedDigitSystemFont(ofSize: UIFont.systemFontSize, weight: UIFont.Weight.bold)], range: msg9Text.range(of: ".attributedText()")) + msg9AttributedText.addAttributes([NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)], range: msg9Text.range(of: "bold")) + msg9AttributedText.addAttributes([NSAttributedStringKey.font: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)], range: msg9Text.range(of: "italic")) + msg9AttributedText.addAttributes([NSAttributedStringKey.foregroundColor: UIColor.red], range: msg9Text.range(of: "colored")) var msg9 = MockMessage(attributedText: msg9AttributedText, sender: Jobs, messageId: UUID().uuidString) var msg10 = MockMessage(text: "1-800-555-0000", sender: Dan, messageId: UUID().uuidString) diff --git a/MessageKit.podspec b/MessageKit.podspec index 02db7826..16a92bd3 100644 --- a/MessageKit.podspec +++ b/MessageKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MessageKit' - s.version = '0.8.1' + s.version = '0.8.2' s.license = { :type => "MIT", :file => "LICENSE.md" } s.summary = 'An elegant messages UI library for iOS.' @@ -12,7 +12,7 @@ Pod::Spec.new do |s| s.source_files = 'Sources/*.swift' s.pod_target_xcconfig = { - "SWIFT_VERSION" => "3.0", + "SWIFT_VERSION" => "4.0", } s.ios.deployment_target = '9.0' diff --git a/MessageKit.xcodeproj/project.pbxproj b/MessageKit.xcodeproj/project.pbxproj index 0a795806..50ab1ed7 100644 --- a/MessageKit.xcodeproj/project.pbxproj +++ b/MessageKit.xcodeproj/project.pbxproj @@ -554,7 +554,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -604,7 +604,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -629,7 +629,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -650,7 +650,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/Sources/AvatarView.swift b/Sources/AvatarView.swift index 12695fda..bf9ed2ef 100644 --- a/Sources/AvatarView.swift +++ b/Sources/AvatarView.swift @@ -102,7 +102,7 @@ open class AvatarView: UIView { let textStyle = NSMutableParagraphStyle() textStyle.alignment = .center - let textFontAttributes: [String: Any] = [NSFontAttributeName: font, NSForegroundColorAttributeName: placeholderTextColor, NSParagraphStyleAttributeName: textStyle] + let textFontAttributes: [NSAttributedStringKey: Any] = [NSAttributedStringKey.font: font, NSAttributedStringKey.foregroundColor: placeholderTextColor, NSAttributedStringKey.paragraphStyle: textStyle] let textTextHeight: CGFloat = initals.boundingRect(with: CGSize(width: textRect.width, height: CGFloat.infinity), options: .usesLineFragmentOrigin, attributes: textFontAttributes, context: nil).height context.saveGState() diff --git a/Sources/InputBarItem.swift b/Sources/InputBarItem.swift index 23854aae..45e3ffce 100644 --- a/Sources/InputBarItem.swift +++ b/Sources/InputBarItem.swift @@ -43,11 +43,11 @@ open class InputBarButtonItem: UIButton { didSet { switch spacing { case .flexible: - setContentHuggingPriority(1, for: .horizontal) + setContentHuggingPriority(UILayoutPriority(rawValue: 1), for: .horizontal) case .fixed: - setContentHuggingPriority(1000, for: .horizontal) + setContentHuggingPriority(UILayoutPriority(rawValue: 1000), for: .horizontal) case .none: - setContentHuggingPriority(500, for: .horizontal) + setContentHuggingPriority(UILayoutPriority(rawValue: 500), for: .horizontal) } } } @@ -144,8 +144,8 @@ open class InputBarButtonItem: UIButton { contentVerticalAlignment = .center contentHorizontalAlignment = .center imageView?.contentMode = .scaleAspectFit - setContentHuggingPriority(500, for: .horizontal) - setContentHuggingPriority(500, for: .vertical) + setContentHuggingPriority(UILayoutPriority(rawValue: 500), for: .horizontal) + setContentHuggingPriority(UILayoutPriority(rawValue: 500), for: .vertical) setTitleColor(UIColor(red: 0, green: 122/255, blue: 1, alpha: 1), for: .normal) setTitleColor(UIColor(red: 0, green: 122/255, blue: 1, alpha: 0.3), for: .highlighted) setTitleColor(.lightGray, for: .disabled) @@ -234,7 +234,7 @@ open class InputBarButtonItem: UIButton { onKeyboardEditingBeginsAction?(self) } - public func touchUpInsideAction() { + @objc public func touchUpInsideAction() { onTouchUpInsideAction?(self) } diff --git a/Sources/MessageCollectionViewCell.swift b/Sources/MessageCollectionViewCell.swift index cbbecac6..055412c9 100644 --- a/Sources/MessageCollectionViewCell.swift +++ b/Sources/MessageCollectionViewCell.swift @@ -164,19 +164,19 @@ open class MessageCollectionViewCell: UICollectionViewCell // MARK: - Delegate Methods - func didTapAvatar() { + @objc func didTapAvatar() { delegate?.didTapAvatar(in: self) } - func didTapMessage() { + @objc func didTapMessage() { delegate?.didTapMessage(in: self) } - func didTapTopLabel() { + @objc func didTapTopLabel() { delegate?.didTapTopLabel(in: self) } - func didTapBottomLabel() { + @objc func didTapBottomLabel() { delegate?.didTapBottomLabel(in: self) } diff --git a/Sources/MessageInputBar.swift b/Sources/MessageInputBar.swift index 01405728..5bb04dda 100644 --- a/Sources/MessageInputBar.swift +++ b/Sources/MessageInputBar.swift @@ -419,11 +419,11 @@ open class MessageInputBar: UIView { // MARK: - Notifications/Hooks - open func orientationDidChange() { + @objc open func orientationDidChange() { invalidateIntrinsicContentSize() } - open func textViewDidChange() { + @objc open func textViewDidChange() { let trimmedText = inputTextView.text.trimmingCharacters(in: .whitespacesAndNewlines) sendButton.isEnabled = !trimmedText.isEmpty @@ -435,11 +435,11 @@ open class MessageInputBar: UIView { invalidateIntrinsicContentSize() } - open func textViewDidBeginEditing() { + @objc open func textViewDidBeginEditing() { self.items.forEach { $0.keyboardEditingBeginsAction() } } - open func textViewDidEndEditing() { + @objc open func textViewDidEndEditing() { self.items.forEach { $0.keyboardEditingEndsAction() } } diff --git a/Sources/MessageKitDateFormatter.swift b/Sources/MessageKitDateFormatter.swift index e111252e..576f3902 100644 --- a/Sources/MessageKitDateFormatter.swift +++ b/Sources/MessageKitDateFormatter.swift @@ -43,7 +43,7 @@ open class MessageKitDateFormatter { return formatter.string(from: date) } - public func attributedString(from date: Date, with attributes: [String: Any]) -> NSAttributedString { + public func attributedString(from date: Date, with attributes: [NSAttributedStringKey: Any]) -> NSAttributedString { let dateString = string(from: date) return NSAttributedString(string: dateString, attributes: attributes) } diff --git a/Sources/MessageLabel.swift b/Sources/MessageLabel.swift index d382fbef..2d48ab12 100644 --- a/Sources/MessageLabel.swift +++ b/Sources/MessageLabel.swift @@ -119,28 +119,28 @@ open class MessageLabel: UILabel, UIGestureRecognizerDelegate { } } - open var addressAttributes: [String: Any] = [:] { + open var addressAttributes: [NSAttributedStringKey: Any] = [:] { didSet { updateAttributes(for: .address) setNeedsDisplay() } } - open var dateAttributes: [String: Any] = [:] { + open var dateAttributes: [NSAttributedStringKey: Any] = [:] { didSet { updateAttributes(for: .date) setNeedsDisplay() } } - open var phoneNumberAttributes: [String: Any] = [:] { + open var phoneNumberAttributes: [NSAttributedStringKey: Any] = [:] { didSet { updateAttributes(for: .phoneNumber) setNeedsDisplay() } } - open var urlAttributes: [String: Any] = [:] { + open var urlAttributes: [NSAttributedStringKey: Any] = [:] { didSet { updateAttributes(for: .url) setNeedsDisplay() @@ -156,10 +156,10 @@ open class MessageLabel: UILabel, UIGestureRecognizerDelegate { self.numberOfLines = 0 self.lineBreakMode = .byWordWrapping - let defaultAttributes: [String: Any] = [ - NSForegroundColorAttributeName: self.textColor, - NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue, - NSUnderlineColorAttributeName: self.textColor + let defaultAttributes: [NSAttributedStringKey: Any] = [ + NSAttributedStringKey.foregroundColor: self.textColor, + NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleSingle.rawValue, + NSAttributedStringKey.underlineColor: self.textColor ] self.addressAttributes = defaultAttributes @@ -210,7 +210,7 @@ open class MessageLabel: UILabel, UIGestureRecognizerDelegate { guard let index = stringIndex(at: touchLocation) else { return true } for (_, ranges) in rangesForDetectors { for (nsRange, _) in ranges { - guard let range = nsRange.toRange() else { return true } + guard let range = Range(nsRange) else { return true } if range.contains(index) { return false } } } @@ -219,7 +219,7 @@ open class MessageLabel: UILabel, UIGestureRecognizerDelegate { guard let index = stringIndex(at: touchLocation) else { return false } for (_, ranges) in rangesForDetectors { for (nsRange, _) in ranges { - guard let range = nsRange.toRange() else { return false } + guard let range = Range(nsRange) else { return false } if range.contains(index) { return true } } } @@ -266,11 +266,11 @@ open class MessageLabel: UILabel, UIGestureRecognizerDelegate { let mutableAttributedString = NSMutableAttributedString(attributedString: text) var textRange = NSRange(location: 0, length: 0) - let paragraphStyle = text.attribute(NSParagraphStyleAttributeName, at: 0, effectiveRange: &textRange) as? NSMutableParagraphStyle ?? NSMutableParagraphStyle() + let paragraphStyle = text.attribute(NSAttributedStringKey.paragraphStyle, at: 0, effectiveRange: &textRange) as? NSMutableParagraphStyle ?? NSMutableParagraphStyle() paragraphStyle.lineBreakMode = lineBreakMode paragraphStyle.alignment = textAlignment - mutableAttributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: textRange) + mutableAttributedString.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraphStyle, range: textRange) return mutableAttributedString @@ -304,7 +304,7 @@ open class MessageLabel: UILabel, UIGestureRecognizerDelegate { } - private func detectorAttributes(for detectorType: DetectorType) -> [String: Any] { + private func detectorAttributes(for detectorType: DetectorType) -> [NSAttributedStringKey: Any] { switch detectorType { case .address: @@ -319,7 +319,7 @@ open class MessageLabel: UILabel, UIGestureRecognizerDelegate { } - private func detectorAttributes(for checkingResultType: NSTextCheckingResult.CheckingType) -> [String: Any] { + private func detectorAttributes(for checkingResultType: NSTextCheckingResult.CheckingType) -> [NSAttributedStringKey: Any] { switch checkingResultType { case NSTextCheckingResult.CheckingType.address: return addressAttributes @@ -413,14 +413,14 @@ open class MessageLabel: UILabel, UIGestureRecognizerDelegate { isUserInteractionEnabled = true } - func handleGesture(_ gesture: UIGestureRecognizer) { + @objc func handleGesture(_ gesture: UIGestureRecognizer) { let touchLocation = gesture.location(ofTouch: 0, in: self) guard let index = stringIndex(at: touchLocation) else { return } for (detectorType, ranges) in rangesForDetectors { for (nsRange, value) in ranges { - guard let range = nsRange.toRange() else { return } + guard let range = Range(nsRange) else { return } if range.contains(index) { handleGesture(for: detectorType, value: value) } diff --git a/Sources/MessagesViewController.swift b/Sources/MessagesViewController.swift index e3e27c98..b98cc138 100644 --- a/Sources/MessagesViewController.swift +++ b/Sources/MessagesViewController.swift @@ -268,7 +268,7 @@ extension MessagesViewController { NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillChangeFrame, object: nil) } - func handleKeyboardDidChangeState(_ notification: Notification) { + @objc func handleKeyboardDidChangeState(_ notification: Notification) { guard let keyboardEndFrame = notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? CGRect else { return } diff --git a/Sources/String+Extensions.swift b/Sources/String+Extensions.swift index e3930408..0bf7760d 100644 --- a/Sources/String+Extensions.swift +++ b/Sources/String+Extensions.swift @@ -29,7 +29,7 @@ extension String { func height(considering width: CGFloat, and font: UIFont) -> CGFloat { let constraintBox = CGSize(width: width, height: .greatestFiniteMagnitude) - let rect = self.boundingRect(with: constraintBox, options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil) + let rect = self.boundingRect(with: constraintBox, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: font], context: nil) return rect.height } @@ -37,7 +37,7 @@ extension String { func width(considering height: CGFloat, and font: UIFont) -> CGFloat { let constraintBox = CGSize(width: .greatestFiniteMagnitude, height: height) - let rect = self.boundingRect(with: constraintBox, options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil) + let rect = self.boundingRect(with: constraintBox, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: font], context: nil) return rect.width }