Skip to content

Commit

Permalink
Update to Swift 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nathantannar4 committed Sep 29, 2018
1 parent 230e067 commit 9a2affc
Show file tree
Hide file tree
Showing 22 changed files with 96 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

# Specify the Xcode version to use.
macos:
xcode: "9.4.1"
xcode: "10.0"

# Define the steps required to build the project.
steps:
Expand Down
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0
4.2
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "Quick/Quick" "v1.2.0"
github "Quick/Nimble" "v7.0.3"
github "MessageKit/MessageInputBar" "0.2.2"
github "Quick/Nimble" "v7.3.1"
github "Quick/Quick" "v1.3.2"
8 changes: 4 additions & 4 deletions MessageKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -756,7 +756,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -785,7 +785,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -810,7 +810,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
17 changes: 8 additions & 9 deletions Sources/Controllers/MessagesViewController+Keyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ extension MessagesViewController {
// MARK: - Register / Unregister Observers

internal func addKeyboardObservers() {
NotificationCenter.default.addObserver(self, selector: #selector(MessagesViewController.handleKeyboardDidChangeState(_:)), name: .UIKeyboardWillChangeFrame, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(MessagesViewController.handleTextViewDidBeginEditing(_:)), name: .UITextViewTextDidBeginEditing, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(MessagesViewController.adjustScrollViewTopInset), name: .UIDeviceOrientationDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(MessagesViewController.handleKeyboardDidChangeState(_:)), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(MessagesViewController.handleTextViewDidBeginEditing(_:)), name: UITextView.textDidBeginEditingNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(MessagesViewController.adjustScrollViewTopInset), name: UIDevice.orientationDidChangeNotification, object: nil)
}

internal func removeKeyboardObservers() {
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillChangeFrame, object: nil)
NotificationCenter.default.removeObserver(self, name: .UITextViewTextDidBeginEditing, object: nil)
NotificationCenter.default.removeObserver(self, name: .UIDeviceOrientationDidChange, object: nil)
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: UITextView.textDidBeginEditingNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: UIDevice.orientationDidChangeNotification, object: nil)
}

// MARK: - Notification Handlers
Expand All @@ -55,7 +55,7 @@ extension MessagesViewController {
private func handleKeyboardDidChangeState(_ notification: Notification) {
guard !isMessagesControllerBeingDismissed else { return }

guard let keyboardStartFrameInScreenCoords = notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? CGRect else { return }
guard let keyboardStartFrameInScreenCoords = notification.userInfo?[UIResponder.keyboardFrameBeginUserInfoKey] as? CGRect else { return }
guard !keyboardStartFrameInScreenCoords.isEmpty else {
// WORKAROUND for what seems to be a bug in iPad's keyboard handling in iOS 11: we receive an extra spurious frame change
// notification when undocking the keyboard, with a zero starting frame and an incorrect end frame. The workaround is to
Expand All @@ -78,7 +78,7 @@ extension MessagesViewController {
// to simply check whether the current keyboard frame, whatever it is (even when undocked), covers the bottom of the collection
// view.

guard let keyboardEndFrameInScreenCoords = notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? CGRect else { return }
guard let keyboardEndFrameInScreenCoords = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return }
let keyboardEndFrame = view.convert(keyboardEndFrameInScreenCoords, from: view.window)

let newBottomInset = requiredScrollViewBottomInset(forKeyboardFrame: keyboardEndFrame)
Expand All @@ -92,7 +92,6 @@ extension MessagesViewController {
messageCollectionViewBottomInset = newBottomInset
}


// MARK: - Inset Computation

@objc
Expand Down
8 changes: 4 additions & 4 deletions Sources/Controllers/MessagesViewController+Menu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ extension MessagesViewController {
// MARK: - Register / Unregister Observers

internal func addMenuControllerObservers() {
NotificationCenter.default.addObserver(self, selector: #selector(MessagesViewController.menuControllerWillShow(_:)), name: .UIMenuControllerWillShowMenu, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(MessagesViewController.menuControllerWillShow(_:)), name: UIMenuController.willShowMenuNotification, object: nil)
}

internal func removeMenuControllerObservers() {
NotificationCenter.default.removeObserver(self, name: .UIMenuControllerWillShowMenu, object: nil)
NotificationCenter.default.removeObserver(self, name: UIMenuController.willShowMenuNotification, object: nil)
}

// MARK: - Notification Handlers
Expand All @@ -46,11 +46,11 @@ extension MessagesViewController {
guard let currentMenuController = notification.object as? UIMenuController,
let selectedIndexPath = selectedIndexPathForMenu else { return }

NotificationCenter.default.removeObserver(self, name: .UIMenuControllerWillShowMenu, object: nil)
NotificationCenter.default.removeObserver(self, name: UIMenuController.willShowMenuNotification, object: nil)
defer {
NotificationCenter.default.addObserver(self,
selector: #selector(MessagesViewController.menuControllerWillShow(_:)),
name: .UIMenuControllerWillShowMenu, object: nil)
name: UIMenuController.willShowMenuNotification, object: nil)
selectedIndexPathForMenu = nil
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Controllers/MessagesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
}

switch kind {
case UICollectionElementKindSectionHeader:
case UICollectionView.elementKindSectionHeader:
return displayDelegate.messageHeaderView(for: indexPath, in: messagesCollectionView)
case UICollectionElementKindSectionFooter:
case UICollectionView.elementKindSectionFooter:
return displayDelegate.messageFooterView(for: indexPath, in: messagesCollectionView)
default:
fatalError(MessageKitError.unrecognizedSectionKind)
Expand Down Expand Up @@ -299,11 +299,11 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {

private func addObservers() {
NotificationCenter.default.addObserver(
self, selector: #selector(clearMemoryCache), name: .UIApplicationDidReceiveMemoryWarning, object: nil)
self, selector: #selector(clearMemoryCache), name: UIApplication.didReceiveMemoryWarningNotification, object: nil)
}

private func removeObservers() {
NotificationCenter.default.removeObserver(self, name: .UIApplicationDidReceiveMemoryWarning, object: nil)
NotificationCenter.default.removeObserver(self, name: UIApplication.didReceiveMemoryWarningNotification, object: nil)
}

@objc private func clearMemoryCache() {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Layout/MessagesCollectionViewFlowLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ open class MessagesCollectionViewFlowLayout: UICollectionViewFlowLayout {

sectionInset = UIEdgeInsets(top: 4, left: 8, bottom: 4, right: 8)

NotificationCenter.default.addObserver(self, selector: #selector(MessagesCollectionViewFlowLayout.handleOrientationChange(_:)), name: .UIDeviceOrientationDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(MessagesCollectionViewFlowLayout.handleOrientationChange(_:)), name: UIDevice.orientationDidChangeNotification, object: nil)
}

required public init?(coder aDecoder: NSCoder) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Models/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: [NSAttributedStringKey: Any]) -> NSAttributedString {
public func attributedString(from date: Date, with attributes: [NSAttributedString.Key: Any]) -> NSAttributedString {
let dateString = string(from: date)
return NSAttributedString(string: dateString, attributes: attributes)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Models/MessageStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum MessageStyle {
case topRight
case bottomRight

internal var imageOrientation: UIImageOrientation {
internal var imageOrientation: UIImage.Orientation {
switch self {
case .bottomRight: return .up
case .bottomLeft: return .upMirrored
Expand Down
4 changes: 2 additions & 2 deletions Sources/Protocols/MessagesDisplayDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public protocol MessagesDisplayDelegate: AnyObject {
/// - detector: The `DetectorType` for the applied attributes.
/// - message: A `MessageType` with a `MessageKind` case of `.text` or `.attributedText` to which the detectors will apply.
/// - indexPath: The `IndexPath` of the cell.
func detectorAttributes(for detector: DetectorType, and message: MessageType, at indexPath: IndexPath) -> [NSAttributedStringKey: Any]
func detectorAttributes(for detector: DetectorType, and message: MessageType, at indexPath: IndexPath) -> [NSAttributedString.Key: Any]

// MARK: - Location Messages

Expand Down Expand Up @@ -221,7 +221,7 @@ public extension MessagesDisplayDelegate {
return []
}

func detectorAttributes(for detector: DetectorType, and message: MessageType, at indexPath: IndexPath) -> [NSAttributedStringKey: Any] {
func detectorAttributes(for detector: DetectorType, and message: MessageType, at indexPath: IndexPath) -> [NSAttributedString.Key: Any] {
return MessageLabel.defaultAttributes
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Views/AvatarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ open class AvatarView: UIImageView {

let textStyle = NSMutableParagraphStyle()
textStyle.alignment = .center
let textFontAttributes: [NSAttributedStringKey: Any] = [NSAttributedStringKey.font: font, NSAttributedStringKey.foregroundColor: placeholderTextColor, NSAttributedStringKey.paragraphStyle: textStyle]
let textFontAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: placeholderTextColor, NSAttributedString.Key.paragraphStyle: textStyle]

let textTextHeight: CGFloat = initials.boundingRect(with: CGSize(width: textRect.width, height: CGFloat.infinity), options: .usesLineFragmentOrigin, attributes: textFontAttributes, context: nil).height
context.saveGState()
Expand Down
4 changes: 2 additions & 2 deletions Sources/Views/Cells/LocationMessageCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import MapKit
open class LocationMessageCell: MessageContentCell {

/// The activity indicator to be displayed while the map image is loading.
open var activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
open var activityIndicator = UIActivityIndicatorView(style: .gray)

/// The image view holding the map image.
open var imageView = UIImageView()
Expand Down Expand Up @@ -68,7 +68,7 @@ open class LocationMessageCell: MessageContentCell {

activityIndicator.startAnimating()

let snapshotOptions = MKMapSnapshotOptions()
let snapshotOptions = MKMapSnapshotter.Options()
snapshotOptions.region = MKCoordinateRegion(center: locationItem.location.coordinate, span: options.span)
snapshotOptions.showsBuildings = options.showsBuildings
snapshotOptions.showsPointsOfInterest = options.showsPointsOfInterest
Expand Down
2 changes: 1 addition & 1 deletion Sources/Views/InsetLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ open class InsetLabel: UILabel {
}

open override func drawText(in rect: CGRect) {
let insetRect = UIEdgeInsetsInsetRect(rect, textInsets)
let insetRect = rect.inset(by: textInsets)
super.drawText(in: insetRect)
}

Expand Down
28 changes: 14 additions & 14 deletions Sources/Views/MessageLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,25 @@ open class MessageLabel: UILabel {

private var attributesNeedUpdate = false

public static var defaultAttributes: [NSAttributedStringKey: Any] = {
public static var defaultAttributes: [NSAttributedString.Key: Any] = {
return [
NSAttributedStringKey.foregroundColor: UIColor.darkText,
NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleSingle.rawValue,
NSAttributedStringKey.underlineColor: UIColor.darkText
NSAttributedString.Key.foregroundColor: UIColor.darkText,
NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue,
NSAttributedString.Key.underlineColor: UIColor.darkText
]
}()

open internal(set) var addressAttributes: [NSAttributedStringKey: Any] = defaultAttributes
open internal(set) var addressAttributes: [NSAttributedString.Key: Any] = defaultAttributes

open internal(set) var dateAttributes: [NSAttributedStringKey: Any] = defaultAttributes
open internal(set) var dateAttributes: [NSAttributedString.Key: Any] = defaultAttributes

open internal(set) var phoneNumberAttributes: [NSAttributedStringKey: Any] = defaultAttributes
open internal(set) var phoneNumberAttributes: [NSAttributedString.Key: Any] = defaultAttributes

open internal(set) var urlAttributes: [NSAttributedStringKey: Any] = defaultAttributes
open internal(set) var urlAttributes: [NSAttributedString.Key: Any] = defaultAttributes

open internal(set) var transitInformationAttributes: [NSAttributedStringKey: Any] = defaultAttributes
open internal(set) var transitInformationAttributes: [NSAttributedString.Key: Any] = defaultAttributes

public func setAttributes(_ attributes: [NSAttributedStringKey: Any], detector: DetectorType) {
public func setAttributes(_ attributes: [NSAttributedString.Key: Any], detector: DetectorType) {
switch detector {
case .phoneNumber:
phoneNumberAttributes = attributes
Expand Down Expand Up @@ -171,7 +171,7 @@ open class MessageLabel: UILabel {

open override func drawText(in rect: CGRect) {

let insetRect = UIEdgeInsetsInsetRect(rect, textInsets)
let insetRect = rect.inset(by: textInsets)
textContainer.size = CGSize(width: insetRect.width, height: rect.height)

let origin = insetRect.origin
Expand Down Expand Up @@ -263,7 +263,7 @@ open class MessageLabel: UILabel {
}
}

private func detectorAttributes(for detectorType: DetectorType) -> [NSAttributedStringKey: Any] {
private func detectorAttributes(for detectorType: DetectorType) -> [NSAttributedString.Key: Any] {

switch detectorType {
case .address:
Expand All @@ -280,7 +280,7 @@ open class MessageLabel: UILabel {

}

private func detectorAttributes(for checkingResultType: NSTextCheckingResult.CheckingType) -> [NSAttributedStringKey: Any] {
private func detectorAttributes(for checkingResultType: NSTextCheckingResult.CheckingType) -> [NSAttributedString.Key: Any] {
switch checkingResultType {
case .address:
return addressAttributes
Expand Down Expand Up @@ -313,7 +313,7 @@ open class MessageLabel: UILabel {
// Enumerate NSAttributedString NSLinks and append ranges
var results: [NSTextCheckingResult] = matches

text.enumerateAttribute(NSAttributedStringKey.link, in: range, options: []) { value, range, _ in
text.enumerateAttribute(NSAttributedString.Key.link, in: range, options: []) { value, range, _ in
guard let url = value as? URL else { return }
let result = NSTextCheckingResult.linkCheckingResult(range: range, url: url)
results.append(result)
Expand Down
8 changes: 4 additions & 4 deletions Sources/Views/MessagesCollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ open class MessagesCollectionView: UICollectionView {
register(TextMessageCell.self)
register(MediaMessageCell.self)
register(LocationMessageCell.self)
register(MessageReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader)
register(MessageReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter)
register(MessageReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader)
register(MessageReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter)
}

private func setupGestureRecognizers() {
Expand Down Expand Up @@ -140,7 +140,7 @@ open class MessagesCollectionView: UICollectionView {

/// Generically dequeues a header of the correct type allowing you to avoid scattering your code with guard-let-else-fatal
public func dequeueReusableHeaderView<T: UICollectionReusableView>(_ viewClass: T.Type, for indexPath: IndexPath) -> T {
let view = dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: String(describing: T.self), for: indexPath)
let view = dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: String(describing: T.self), for: indexPath)
guard let viewType = view as? T else {
fatalError("Unable to dequeue \(String(describing: viewClass)) with reuseId of \(String(describing: T.self))")
}
Expand All @@ -149,7 +149,7 @@ open class MessagesCollectionView: UICollectionView {

/// Generically dequeues a footer of the correct type allowing you to avoid scattering your code with guard-let-else-fatal
public func dequeueReusableFooterView<T: UICollectionReusableView>(_ viewClass: T.Type, for indexPath: IndexPath) -> T {
let view = dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionFooter, withReuseIdentifier: String(describing: T.self), for: indexPath)
let view = dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: String(describing: T.self), for: indexPath)
guard let viewType = view as? T else {
fatalError("Unable to dequeue \(String(describing: viewClass)) with reuseId of \(String(describing: T.self))")
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Views/PlayButtonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open class PlayButtonView: UIView {

// MARK: - Properties

open let triangleView = UIView()
public let triangleView = UIView()

private var triangleCenterXConstraint: NSLayoutConstraint?
private var cacheFrame: CGRect = .zero
Expand Down
2 changes: 1 addition & 1 deletion Tests/ControllersTest/MessageLabelSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ final class MessageLabelSpec: QuickSpec {

fileprivate extension MessageLabel {

var textAttributes: [NSAttributedStringKey: Any] {
var textAttributes: [NSAttributedString.Key: Any] {
let length = attributedText!.length
var range = NSRange(location: 0, length: length)
return attributedText!.attributes(at: 0, effectiveRange: &range)
Expand Down
2 changes: 1 addition & 1 deletion Tests/ControllersTest/MessagesViewControllerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final class MessagesViewControllerSpec: QuickSpec {
}
it("sets keyboardDismissMode to .interactive") {
let dismissMode = controller.messagesCollectionView.keyboardDismissMode
expect(dismissMode).to(equal(UIScrollViewKeyboardDismissMode.interactive))
expect(dismissMode).to(equal(UIScrollView.KeyboardDismissMode.interactive))
}
it("sets alwaysBounceVertical to true") {
expect(controller.messagesCollectionView.alwaysBounceVertical).to(beTrue())
Expand Down
Loading

0 comments on commit 9a2affc

Please sign in to comment.