Updates to Swift 2.2

This commit is contained in:
Diego Sanchez 2016-03-24 23:59:04 +00:00
parent e44c72183b
commit eb84520fff
13 changed files with 22 additions and 28 deletions

View File

@ -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
}

View File

@ -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 {

View File

@ -55,7 +55,7 @@ public struct ReadOnlyOrderedDictionary<T where T: UniqueIdentificable>: Collect
public func generate() -> AnyGenerator<T> {
var index = 0
return anyGenerator({
return AnyGenerator(body: {
guard index < self.items.count else {
return nil
}

View File

@ -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<BubbleViewT, ViewModelBuilderT, InteractionHan
return false
}
cell.bubbleView.userInteractionEnabled = false // This is a hack for UITextView, shouldn't harm to all bubbles
NSNotificationCenter.defaultCenter().addObserver(self, selector: "willShowMenu:", name: UIMenuControllerWillShowMenuNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(BaseMessagePresenter.willShowMenu(_:)), name: UIMenuControllerWillShowMenuNotification, object: nil)
return true
}

View File

@ -137,12 +137,12 @@ public class BaseMessageCollectionViewCell<BubbleViewType where BubbleViewType:U
}
public private(set) lazy var tapGestureRecognizer: UITapGestureRecognizer = {
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "bubbleTapped:")
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(BaseMessageCollectionViewCell.bubbleTapped(_:)))
return tapGestureRecognizer
}()
public private (set) lazy var longPressGestureRecognizer: UILongPressGestureRecognizer = {
let longpressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: "bubbleLongPressed:")
let longpressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(BaseMessageCollectionViewCell.bubbleLongPressed(_:)))
longpressGestureRecognizer.delegate = self
return longpressGestureRecognizer
}()
@ -174,7 +174,7 @@ public class BaseMessageCollectionViewCell<BubbleViewType where BubbleViewType:U
private lazy var failedButton: UIButton = {
let button = UIButton(type: .Custom)
button.addTarget(self, action: "failedButtonTapped", forControlEvents: .TouchUpInside)
button.addTarget(self, action: #selector(BaseMessageCollectionViewCell.failedButtonTapped), forControlEvents: .TouchUpInside)
return button
}()

View File

@ -41,7 +41,4 @@ public class PhotoMessageModel<MessageModelT: MessageModelProtocol>: 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 }
}

View File

@ -83,7 +83,7 @@ public class PhotoMessagePresenter<ViewModelBuilderT, InteractionHandlerT where
return nil
}
public override func configureCell(cell: BaseMessageCollectionViewCell<PhotoBubbleView>, decorationAttributes: ChatItemDecorationAttributes, animated: Bool, additionalConfiguration: (() -> Void)?) {
public override func configureCell(cell: BaseMessageCollectionViewCell<PhotoBubbleView>, decorationAttributes: ChatItemDecorationAttributes, animated: Bool, additionalConfiguration: (() -> Void)?) {
guard let cell = cell as? PhotoMessageCollectionViewCell else {
assert(false, "Invalid cell received")
return

View File

@ -38,7 +38,4 @@ public class TextMessageModel<MessageModelT: MessageModelProtocol>: 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 }
}

View File

@ -65,7 +65,7 @@ public class TextMessagePresenter<ViewModelBuilderT, InteractionHandlerT where
return collectionView.dequeueReusableCellWithReuseIdentifier(identifier, forIndexPath: indexPath)
}
public override func configureCell(cell: BaseMessageCollectionViewCell<TextBubbleView>, decorationAttributes: ChatItemDecorationAttributes, animated: Bool, additionalConfiguration: (() -> Void)?) {
public override func configureCell(cell: BaseMessageCollectionViewCell<TextBubbleView>, 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<ViewModelBuilderT, InteractionHandlerT where
}
public override func canPerformMenuControllerAction(action: Selector) -> 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")

View File

@ -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)
}

View File

@ -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()
}

View File

@ -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() {

View File

@ -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