Update Example to Swift 4.2

This commit is contained in:
Nathan Tannar
2018-09-29 12:24:01 -07:00
parent dbf9d65d14
commit d806da72e0
13 changed files with 47 additions and 47 deletions
@@ -201,7 +201,7 @@ final class AdvancedExampleViewController: ChatViewController {
// MARK: - UICollectionViewDataSource
open override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
public override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let messagesDataSource = messagesCollectionView.messagesDataSource else {
fatalError("Ouch. nil data source for messages")
@@ -224,7 +224,7 @@ final class AdvancedExampleViewController: ChatViewController {
override func cellTopLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? {
if isTimeLabelVisible(at: indexPath) {
return NSAttributedString(string: MessageKitDateFormatter.shared.string(from: message.sentDate), attributes: [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 10), NSAttributedStringKey.foregroundColor: UIColor.darkGray])
return NSAttributedString(string: MessageKitDateFormatter.shared.string(from: message.sentDate), attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 10), NSAttributedString.Key.foregroundColor: UIColor.darkGray])
}
return nil
}
@@ -232,7 +232,7 @@ final class AdvancedExampleViewController: ChatViewController {
override func messageTopLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? {
if !isPreviousMessageSameSender(at: indexPath) {
let name = message.sender.displayName
return NSAttributedString(string: name, attributes: [NSAttributedStringKey.font: UIFont.preferredFont(forTextStyle: .caption1)])
return NSAttributedString(string: name, attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .caption1)])
}
return nil
}
@@ -240,7 +240,7 @@ final class AdvancedExampleViewController: ChatViewController {
override func messageBottomLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? {
if !isNextMessageSameSender(at: indexPath) && isFromCurrentSender(message: message) {
return NSAttributedString(string: "Delivered", attributes: [NSAttributedStringKey.font: UIFont.preferredFont(forTextStyle: .caption1)])
return NSAttributedString(string: "Delivered", attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .caption1)])
}
return nil
}
@@ -257,7 +257,7 @@ extension AdvancedExampleViewController: MessagesDisplayDelegate {
return isFromCurrentSender(message: message) ? .white : .darkText
}
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
}
@@ -48,7 +48,7 @@ extension BasicExampleViewController: MessagesDisplayDelegate {
return isFromCurrentSender(message: message) ? .white : .darkText
}
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
}
@@ -147,7 +147,6 @@ class ChatViewController: MessagesViewController, MessagesDataSource {
return visibleRect.contains(rect)
}
// MARK: - MessagesDataSource
func currentSender() -> Sender {
@@ -164,20 +163,20 @@ class ChatViewController: MessagesViewController, MessagesDataSource {
func cellTopLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? {
if indexPath.section % 3 == 0 {
return NSAttributedString(string: MessageKitDateFormatter.shared.string(from: message.sentDate), attributes: [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 10), NSAttributedStringKey.foregroundColor: UIColor.darkGray])
return NSAttributedString(string: MessageKitDateFormatter.shared.string(from: message.sentDate), attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 10), NSAttributedString.Key.foregroundColor: UIColor.darkGray])
}
return nil
}
func messageTopLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? {
let name = message.sender.displayName
return NSAttributedString(string: name, attributes: [NSAttributedStringKey.font: UIFont.preferredFont(forTextStyle: .caption1)])
return NSAttributedString(string: name, attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .caption1)])
}
func messageBottomLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? {
let dateString = formatter.string(from: message.sentDate)
return NSAttributedString(string: dateString, attributes: [NSAttributedStringKey.font: UIFont.preferredFont(forTextStyle: .caption2)])
return NSAttributedString(string: dateString, attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .caption2)])
}
}
@@ -56,10 +56,10 @@ final class MessageContainerController: UIViewController {
super.viewDidLoad()
/// Add the `ConversationViewController` as a child view controller
conversationViewController.willMove(toParentViewController: self)
self.addChildViewController(conversationViewController)
conversationViewController.willMove(toParent: self)
self.addChild(conversationViewController)
view.addSubview(conversationViewController.view)
conversationViewController.didMove(toParentViewController: self)
conversationViewController.didMove(toParent: self)
view.addSubview(mapView)
view.addSubview(bannerView)