From eb84520fff31cfdbc8226bb1bc582b28f13ce03f Mon Sep 17 00:00:00 2001 From: Diego Sanchez Date: Thu, 24 Mar 2016 23:59:04 +0000 Subject: [PATCH] Updates to Swift 2.2 --- .../Collaborators/AccessoryViewRevealer.swift | 2 +- .../ChatController/Collaborators/KeyboardTracker.swift | 8 ++++---- Chatto/Source/ReadOnlyOrderedDictionary.swift | 2 +- .../Chat Items/BaseMessage/BaseMessagePresenter.swift | 8 ++++---- .../BaseMessage/Views/BaseMessageCollectionViewCell.swift | 6 +++--- .../Chat Items/PhotoMessages/PhotoMessageModel.swift | 3 --- .../Chat Items/PhotoMessages/PhotoMessagePresenter.swift | 2 +- .../Source/Chat Items/TextMessages/TextMessageModel.swift | 3 --- .../Chat Items/TextMessages/TextMessagePresenter.swift | 6 +++--- ChattoAdditions/Source/Input/ChatInputItemView.swift | 2 +- ChattoAdditions/Source/Input/ExpandableTextView.swift | 2 +- ChattoAdditions/Source/Input/Photos/LiveCameraCell.swift | 4 ++-- .../TextMessages/TextMessagePresenterTests.swift | 2 +- 13 files changed, 22 insertions(+), 28 deletions(-) diff --git a/Chatto/Source/ChatController/Collaborators/AccessoryViewRevealer.swift b/Chatto/Source/ChatController/Collaborators/AccessoryViewRevealer.swift index 560182c..57dc229 100644 --- a/Chatto/Source/ChatController/Collaborators/AccessoryViewRevealer.swift +++ b/Chatto/Source/ChatController/Collaborators/AccessoryViewRevealer.swift @@ -38,7 +38,7 @@ class AccessoryViewRevealer: NSObject, UIGestureRecognizerDelegate { self.collectionView = collectionView super.init() self.collectionView.addGestureRecognizer(self.panRecognizer) - self.panRecognizer.addTarget(self, action: "handlePan:") + self.panRecognizer.addTarget(self, action: #selector(AccessoryViewRevealer.handlePan(_:))) self.panRecognizer.delegate = self } diff --git a/Chatto/Source/ChatController/Collaborators/KeyboardTracker.swift b/Chatto/Source/ChatController/Collaborators/KeyboardTracker.swift index b36310e..7c95fb0 100644 --- a/Chatto/Source/ChatController/Collaborators/KeyboardTracker.swift +++ b/Chatto/Source/ChatController/Collaborators/KeyboardTracker.swift @@ -55,10 +55,10 @@ class KeyboardTracker { self.inputContainer = inputContainer self.inputContainerBottomConstraint = inputContainerBottomContraint self.notificationCenter = notificationCenter - self.notificationCenter.addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil) - self.notificationCenter.addObserver(self, selector: "keyboardDidShow:", name: UIKeyboardDidShowNotification, object: nil) - self.notificationCenter.addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil) - self.notificationCenter.addObserver(self, selector: "keyboardWillChangeFrame:", name: UIKeyboardWillChangeFrameNotification, object: nil) + self.notificationCenter.addObserver(self, selector: #selector(KeyboardTracker.keyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object: nil) + self.notificationCenter.addObserver(self, selector: #selector(KeyboardTracker.keyboardDidShow(_:)), name: UIKeyboardDidShowNotification, object: nil) + self.notificationCenter.addObserver(self, selector: #selector(KeyboardTracker.keyboardWillHide(_:)), name: UIKeyboardWillHideNotification, object: nil) + self.notificationCenter.addObserver(self, selector: #selector(KeyboardTracker.keyboardWillChangeFrame(_:)), name: UIKeyboardWillChangeFrameNotification, object: nil) } deinit { diff --git a/Chatto/Source/ReadOnlyOrderedDictionary.swift b/Chatto/Source/ReadOnlyOrderedDictionary.swift index 3c4feb6..9f5dc70 100644 --- a/Chatto/Source/ReadOnlyOrderedDictionary.swift +++ b/Chatto/Source/ReadOnlyOrderedDictionary.swift @@ -55,7 +55,7 @@ public struct ReadOnlyOrderedDictionary: Collect public func generate() -> AnyGenerator { var index = 0 - return anyGenerator({ + return AnyGenerator(body: { guard index < self.items.count else { return nil } diff --git a/ChattoAdditions/Source/Chat Items/BaseMessage/BaseMessagePresenter.swift b/ChattoAdditions/Source/Chat Items/BaseMessage/BaseMessagePresenter.swift index 300b323..9a57b02 100644 --- a/ChattoAdditions/Source/Chat Items/BaseMessage/BaseMessagePresenter.swift +++ b/ChattoAdditions/Source/Chat Items/BaseMessage/BaseMessagePresenter.swift @@ -26,14 +26,14 @@ import Foundation import Chatto public protocol ViewModelBuilderProtocol { - typealias ModelT: MessageModelProtocol - typealias ViewModelT: MessageViewModelProtocol + associatedtype ModelT: MessageModelProtocol + associatedtype ViewModelT: MessageViewModelProtocol func canCreateViewModel(fromModel model: Any) -> Bool func createViewModel(model: ModelT) -> ViewModelT } public protocol BaseMessageInteractionHandlerProtocol { - typealias ViewModelT + associatedtype ViewModelT func userDidTapOnFailIcon(viewModel viewModel: ViewModelT) func userDidTapOnBubble(viewModel viewModel: ViewModelT) func userDidLongPressOnBubble(viewModel viewModel: ViewModelT) @@ -134,7 +134,7 @@ public class BaseMessagePresenter: PhotoMessag self.imageSize = imageSize self.image = image } - - // This should be covered by DecoratedMessageModelProtocol, but compiler crashes without this (Xcode 7.1) - public var uid: String { return self.messageModel.uid } } diff --git a/ChattoAdditions/Source/Chat Items/PhotoMessages/PhotoMessagePresenter.swift b/ChattoAdditions/Source/Chat Items/PhotoMessages/PhotoMessagePresenter.swift index 4487bff..1410cd6 100644 --- a/ChattoAdditions/Source/Chat Items/PhotoMessages/PhotoMessagePresenter.swift +++ b/ChattoAdditions/Source/Chat Items/PhotoMessages/PhotoMessagePresenter.swift @@ -83,7 +83,7 @@ public class PhotoMessagePresenter, decorationAttributes: ChatItemDecorationAttributes, animated: Bool, additionalConfiguration: (() -> Void)?) { + public override func configureCell(cell: BaseMessageCollectionViewCell, decorationAttributes: ChatItemDecorationAttributes, animated: Bool, additionalConfiguration: (() -> Void)?) { guard let cell = cell as? PhotoMessageCollectionViewCell else { assert(false, "Invalid cell received") return diff --git a/ChattoAdditions/Source/Chat Items/TextMessages/TextMessageModel.swift b/ChattoAdditions/Source/Chat Items/TextMessages/TextMessageModel.swift index 785fb13..2d4c020 100644 --- a/ChattoAdditions/Source/Chat Items/TextMessages/TextMessageModel.swift +++ b/ChattoAdditions/Source/Chat Items/TextMessages/TextMessageModel.swift @@ -38,7 +38,4 @@ public class TextMessageModel: TextMessageM self._messageModel = messageModel self.text = text } - // This should be covered by DecoratedMessageModelProtocol, but compiler crashes without this (Xcode 7.1) - public var uid: String { return self.messageModel.uid } - } diff --git a/ChattoAdditions/Source/Chat Items/TextMessages/TextMessagePresenter.swift b/ChattoAdditions/Source/Chat Items/TextMessages/TextMessagePresenter.swift index 1e8f452..149f13a 100644 --- a/ChattoAdditions/Source/Chat Items/TextMessages/TextMessagePresenter.swift +++ b/ChattoAdditions/Source/Chat Items/TextMessages/TextMessagePresenter.swift @@ -65,7 +65,7 @@ public class TextMessagePresenter, decorationAttributes: ChatItemDecorationAttributes, animated: Bool, additionalConfiguration: (() -> Void)?) { + public override func configureCell(cell: BaseMessageCollectionViewCell, decorationAttributes: ChatItemDecorationAttributes, animated: Bool, additionalConfiguration: (() -> Void)?) { guard let cell = cell as? TextMessageCollectionViewCell else { assert(false, "Invalid cell received") return @@ -84,11 +84,11 @@ public class TextMessagePresenter Bool { - return action == "copy:" + return action == #selector(NSObject.copy(_:)) } public override func performMenuControllerAction(action: Selector) { - if action == "copy:" { + if action == #selector(NSObject.copy(_:)) { UIPasteboard.generalPasteboard().string = self.messageViewModel.text } else { assert(false, "Unexpected action") diff --git a/ChattoAdditions/Source/Input/ChatInputItemView.swift b/ChattoAdditions/Source/Input/ChatInputItemView.swift index c66712a..2badb0c 100644 --- a/ChattoAdditions/Source/Input/ChatInputItemView.swift +++ b/ChattoAdditions/Source/Input/ChatInputItemView.swift @@ -40,7 +40,7 @@ class ChatInputItemView: UIView { } private func commonInit() { - let gestureRecognizer = UITapGestureRecognizer(target: self, action: "handleTap") + let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(ChatInputItemView.handleTap)) gestureRecognizer.cancelsTouchesInView = false self.addGestureRecognizer(gestureRecognizer) } diff --git a/ChattoAdditions/Source/Input/ExpandableTextView.swift b/ChattoAdditions/Source/Input/ExpandableTextView.swift index 1bb6fbe..0066221 100644 --- a/ChattoAdditions/Source/Input/ExpandableTextView.swift +++ b/ChattoAdditions/Source/Input/ExpandableTextView.swift @@ -45,7 +45,7 @@ public class ExpandableTextView: UITextView { } private func commonInit() { - NSNotificationCenter.defaultCenter().addObserver(self, selector: "textDidChange", name: UITextViewTextDidChangeNotification, object: self) + NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ExpandableTextView.textDidChange), name: UITextViewTextDidChangeNotification, object: self) self.configurePlaceholder() self.updatePlaceholderVisibility() } diff --git a/ChattoAdditions/Source/Input/Photos/LiveCameraCell.swift b/ChattoAdditions/Source/Input/Photos/LiveCameraCell.swift index 7ea068d..6d52626 100644 --- a/ChattoAdditions/Source/Input/Photos/LiveCameraCell.swift +++ b/ChattoAdditions/Source/Input/Photos/LiveCameraCell.swift @@ -154,8 +154,8 @@ class LiveCameraCell: UICollectionViewCell { }() private func subscribeToAppNotifications() { - self.notificationCenter.addObserver(self, selector: "handleWillResignActiveNotification", name: UIApplicationWillResignActiveNotification, object: nil) - self.notificationCenter.addObserver(self, selector: "handleDidBecomeActiveNotification", name: UIApplicationDidBecomeActiveNotification, object: nil) + self.notificationCenter.addObserver(self, selector: #selector(LiveCameraCell.handleWillResignActiveNotification), name: UIApplicationWillResignActiveNotification, object: nil) + self.notificationCenter.addObserver(self, selector: #selector(LiveCameraCell.handleDidBecomeActiveNotification), name: UIApplicationDidBecomeActiveNotification, object: nil) } private func unsubscribeFromAppNotifications() { diff --git a/ChattoAdditions/Tests/Chat Items/TextMessages/TextMessagePresenterTests.swift b/ChattoAdditions/Tests/Chat Items/TextMessages/TextMessagePresenterTests.swift index 9a60aaf..5ee72d5 100644 --- a/ChattoAdditions/Tests/Chat Items/TextMessages/TextMessagePresenterTests.swift +++ b/ChattoAdditions/Tests/Chat Items/TextMessages/TextMessagePresenterTests.swift @@ -72,7 +72,7 @@ class TextMessagePresenterTests: XCTestCase, UICollectionViewDataSource { } func testThat_CanPerformCopyAction() { - XCTAssertTrue(self.presenter.canPerformMenuControllerAction(Selector("copy:"))) + XCTAssertTrue(self.presenter.canPerformMenuControllerAction(#selector(NSObject.copy(_:)))) } // MARK: Helpers