Skip to content

Commit

Permalink
Xcode 9 & Swift 4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Sepho committed Sep 23, 2017
1 parent cee315f commit c4aaab1
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 39 deletions.
8 changes: 4 additions & 4 deletions MessageKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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";
Expand All @@ -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;
};
Expand All @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion Sources/AvatarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions Sources/InputBarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -234,7 +234,7 @@ open class InputBarButtonItem: UIButton {
onKeyboardEditingBeginsAction?(self)
}

public func touchUpInsideAction() {
@objc public func touchUpInsideAction() {
onTouchUpInsideAction?(self)
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/MessageCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,19 @@ open class MessageCollectionViewCell<ContentView: UIView>: 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)
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/MessageInputBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() }
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/MessageKitDateFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
32 changes: 16 additions & 16 deletions Sources/MessageLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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 }
}
}
Expand All @@ -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 }
}
}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/MessagesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
4 changes: 2 additions & 2 deletions Sources/String+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ 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

}

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

}
Expand Down

0 comments on commit c4aaab1

Please sign in to comment.