Updates to Swift 2.2
This commit is contained in:
parent
e44c72183b
commit
eb84520fff
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}()
|
||||
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue