Skip to content

Commit

Permalink
Migrated to Swift 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Schukin committed Oct 8, 2018
1 parent 26ae997 commit bed6a0a
Show file tree
Hide file tree
Showing 42 changed files with 648 additions and 583 deletions.
2 changes: 1 addition & 1 deletion .swift-version
@@ -1 +1 @@
4.0.0
4.2.0
2 changes: 1 addition & 1 deletion Chatto.podspec
Expand Up @@ -13,5 +13,5 @@ Pod::Spec.new do |s|
s.source_files = "Chatto/Source/**/*.{h,m,swift}"
s.public_header_files = "Chatto/Source/**/*.h"
s.requires_arc = true
# s.resources = ["Chatto/Source/**/*.xib", "Chatto/Source/**/*.storyboard", "Chatto/Source/**/*.xcassets"]
s.swift_version = '4.2'
end
8 changes: 3 additions & 5 deletions Chatto/Chatto.xcodeproj/project.pbxproj
Expand Up @@ -275,7 +275,7 @@
TargetAttributes = {
C32BB71F1BE0504D0069EC50 = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0900;
LastSwiftMigration = 1000;
};
C32BB7291BE0504D0069EC50 = {
CreatedOnToolsVersion = 7.1;
Expand Down Expand Up @@ -514,8 +514,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.Chatto;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -534,8 +533,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.Chatto;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
6 changes: 3 additions & 3 deletions Chatto/Source/ChatController/BaseChatViewController.swift
Expand Up @@ -140,7 +140,7 @@ open class BaseChatViewController: UIViewController, UICollectionViewDataSource,
self.collectionView.showsHorizontalScrollIndicator = false
self.collectionView.allowsSelection = false
self.collectionView.translatesAutoresizingMaskIntoConstraints = false
self.collectionView.autoresizingMask = UIViewAutoresizing()
self.collectionView.autoresizingMask = []
self.view.addSubview(self.collectionView)
self.view.addConstraint(NSLayoutConstraint(item: self.view, attribute: .top, relatedBy: .equal, toItem: self.collectionView, attribute: .top, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: self.view, attribute: .leading, relatedBy: .equal, toItem: self.collectionView, attribute: .leading, multiplier: 1, constant: 0))
Expand All @@ -162,7 +162,7 @@ open class BaseChatViewController: UIViewController, UICollectionViewDataSource,
private var inputContainerBottomConstraint: NSLayoutConstraint!
private func addInputViews() {
self.inputContainer = UIView(frame: CGRect.zero)
self.inputContainer.autoresizingMask = UIViewAutoresizing()
self.inputContainer.autoresizingMask = []
self.inputContainer.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(self.inputContainer)
self.view.addConstraint(NSLayoutConstraint(item: self.inputContainer, attribute: .top, relatedBy: .greaterThanOrEqual, toItem: self.topLayoutGuide, attribute: .bottom, multiplier: 1, constant: 0))
Expand All @@ -181,7 +181,7 @@ open class BaseChatViewController: UIViewController, UICollectionViewDataSource,

private func addBottomSpaceView() {
self.bottomSpaceView = UIView(frame: CGRect.zero)
self.bottomSpaceView.autoresizingMask = UIViewAutoresizing()
self.bottomSpaceView.autoresizingMask = []
self.bottomSpaceView.translatesAutoresizingMaskIntoConstraints = false
self.bottomSpaceView.backgroundColor = UIColor.white
self.view.addSubview(self.bottomSpaceView)
Expand Down
37 changes: 31 additions & 6 deletions Chatto/Source/ChatController/Collaborators/KeyboardTracker.swift
Expand Up @@ -60,11 +60,36 @@ class KeyboardTracker {
self.layoutBlock = layoutBlock
self.inputContainer = inputContainer
self.notificationCenter = notificationCenter
self.notificationCenter.addObserver(self, selector: #selector(KeyboardTracker.keyboardWillShow(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
self.notificationCenter.addObserver(self, selector: #selector(KeyboardTracker.keyboardDidShow(_:)), name: NSNotification.Name.UIKeyboardDidShow, object: nil)
self.notificationCenter.addObserver(self, selector: #selector(KeyboardTracker.keyboardWillHide(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
self.notificationCenter.addObserver(self, selector: #selector(KeyboardTracker.keyboardDidHide(_:)), name: NSNotification.Name.UIKeyboardDidHide, object: nil)
self.notificationCenter.addObserver(self, selector: #selector(KeyboardTracker.keyboardWillChangeFrame(_:)), name: NSNotification.Name.UIKeyboardWillChangeFrame, object: nil)
self.notificationCenter.addObserver(
self,
selector: #selector(KeyboardTracker.keyboardWillShow(_:)),
name: UIResponder.keyboardWillShowNotification,
object: nil
)
self.notificationCenter.addObserver(
self,
selector: #selector(KeyboardTracker.keyboardDidShow(_:)),
name: UIResponder.keyboardDidShowNotification,
object: nil
)
self.notificationCenter.addObserver(
self,
selector: #selector(KeyboardTracker.keyboardWillHide(_:)),
name: UIResponder.keyboardWillHideNotification,
object: nil
)
self.notificationCenter.addObserver(
self,
selector: #selector(KeyboardTracker.keyboardDidHide(_:)),
name: UIResponder.keyboardDidHideNotification,
object: nil
)
self.notificationCenter.addObserver(
self,
selector: #selector(KeyboardTracker.keyboardWillChangeFrame(_:)),
name: UIResponder.keyboardWillChangeFrameNotification,
object: nil
)
}

deinit {
Expand Down Expand Up @@ -126,7 +151,7 @@ class KeyboardTracker {
}

private func bottomConstraintFromNotification(_ notification: Notification) -> CGFloat {
guard let rect = ((notification as NSNotification).userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return 0 }
guard let rect = ((notification as NSNotification).userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return 0 }
guard rect.height > 0 else { return 0 }
let rectInView = self.view.convert(rect, from: nil)
guard rectInView.maxY >=~ self.view.bounds.height else { return 0 } // Undocked keyboard
Expand Down
1 change: 1 addition & 0 deletions ChattoAdditions.podspec
Expand Up @@ -14,6 +14,7 @@ Pod::Spec.new do |s|
s.source_files = "ChattoAdditions/Source/**/*.{h,m,swift}"
s.public_header_files = "ChattoAdditions/Source/**/*.h"
s.requires_arc = true
s.swift_version = '4.2'
s.resources = ["ChattoAdditions/Source/**/*.xib", "ChattoAdditions/Source/**/*.storyboard", "ChattoAdditions/Source/**/*.xcassets"]
s.dependency 'Chatto'
end
10 changes: 6 additions & 4 deletions ChattoAdditions/ChattoAdditions.xcodeproj/project.pbxproj
Expand Up @@ -622,9 +622,11 @@
TargetAttributes = {
C3C0CBB71BFE49320052747C = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 1000;
};
C3C0CBC11BFE49320052747C = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 1000;
};
};
};
Expand Down Expand Up @@ -923,7 +925,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.ChattoAdditions;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -941,7 +943,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.ChattoAdditions;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand All @@ -952,7 +954,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.ChattoAdditionsTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -963,7 +965,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.ChattoAdditionsTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
Expand Up @@ -163,13 +163,13 @@ open class BaseMessagePresenter<BubbleViewT, ViewModelBuilderT, InteractionHandl
return false
}
cell.bubbleView.isUserInteractionEnabled = false // This is a hack for UITextView, shouldn't harm to all bubbles
NotificationCenter.default.addObserver(self, selector: #selector(BaseMessagePresenter.willShowMenu(_:)), name: NSNotification.Name.UIMenuControllerWillShowMenu, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(BaseMessagePresenter.willShowMenu(_:)), name: UIMenuController.willShowMenuNotification, object: nil)
return true
}

@objc
func willShowMenu(_ notification: Notification) {
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIMenuControllerWillShowMenu, object: nil)
NotificationCenter.default.removeObserver(self, name: UIMenuController.willShowMenuNotification, object: nil)
guard let cell = self.cell, let menuController = notification.object as? UIMenuController else {
assert(false, "Investigate -> Fix or remove assert")
return
Expand Down
Expand Up @@ -109,13 +109,13 @@ open class BaseMessageCollectionViewCellDefaultStyle: BaseMessageCollectionViewC
let selectionIndicatorStyle: SelectionIndicatorStyle

public init(
colors: Colors = Class.createDefaultColors(),
bubbleBorderImages: BubbleBorderImages? = Class.createDefaultBubbleBorderImages(),
failedIconImages: FailedIconImages = Class.createDefaultFailedIconImages(),
layoutConstants: BaseMessageCollectionViewCellLayoutConstants = Class.createDefaultLayoutConstants(),
dateTextStyle: DateTextStyle = Class.createDefaultDateTextStyle(),
colors: Colors = BaseMessageCollectionViewCellDefaultStyle.createDefaultColors(),
bubbleBorderImages: BubbleBorderImages? = BaseMessageCollectionViewCellDefaultStyle.createDefaultBubbleBorderImages(),
failedIconImages: FailedIconImages = BaseMessageCollectionViewCellDefaultStyle.createDefaultFailedIconImages(),
layoutConstants: BaseMessageCollectionViewCellLayoutConstants = BaseMessageCollectionViewCellDefaultStyle.createDefaultLayoutConstants(),
dateTextStyle: DateTextStyle = BaseMessageCollectionViewCellDefaultStyle.createDefaultDateTextStyle(),
avatarStyle: AvatarStyle = AvatarStyle(),
selectionIndicatorStyle: SelectionIndicatorStyle = Class.createDefaultSelectionIndicatorStyle()) {
selectionIndicatorStyle: SelectionIndicatorStyle = BaseMessageCollectionViewCellDefaultStyle.createDefaultSelectionIndicatorStyle()) {
self.colors = colors
self.bubbleBorderImages = bubbleBorderImages
self.failedIconImages = failedIconImages
Expand All @@ -125,8 +125,8 @@ open class BaseMessageCollectionViewCellDefaultStyle: BaseMessageCollectionViewC
self.selectionIndicatorStyle = selectionIndicatorStyle

self.dateStringAttributes = [
NSAttributedStringKey.font: self.dateTextStyle.font(),
NSAttributedStringKey.foregroundColor: self.dateTextStyle.color()
NSAttributedString.Key.font: self.dateTextStyle.font(),
NSAttributedString.Key.foregroundColor: self.dateTextStyle.color()
]
}

Expand All @@ -141,7 +141,7 @@ open class BaseMessageCollectionViewCellDefaultStyle: BaseMessageCollectionViewC
public lazy var failedIcon: UIImage = self.failedIconImages.normal()
public lazy var failedIconHighlighted: UIImage = self.failedIconImages.highlighted()

private let dateStringAttributes: [NSAttributedStringKey: AnyObject]
private let dateStringAttributes: [NSAttributedString.Key: AnyObject]

open func attributedStringForDate(_ date: String) -> NSAttributedString {
return NSAttributedString(string: date, attributes: self.dateStringAttributes)
Expand Down
Expand Up @@ -61,10 +61,9 @@ open class PhotoBubbleView: UIView, MaximumLayoutWidthSpecificable, BackgroundSi

public private(set) lazy var imageView: UIImageView = {
let imageView = UIImageView()
imageView.autoresizingMask = UIViewAutoresizing()
imageView.autoresizingMask = []
imageView.clipsToBounds = true
imageView.autoresizesSubviews = false
imageView.autoresizingMask = UIViewAutoresizing()
imageView.contentMode = .scaleAspectFill
imageView.addSubview(self.borderView)
return imageView
Expand All @@ -83,7 +82,7 @@ open class PhotoBubbleView: UIView, MaximumLayoutWidthSpecificable, BackgroundSi

private var placeholderIconView: UIImageView = {
let imageView = UIImageView()
imageView.autoresizingMask = UIViewAutoresizing()
imageView.autoresizingMask = []
return imageView
}()

Expand Down
Expand Up @@ -89,9 +89,9 @@ open class PhotoMessageCollectionViewCellDefaultStyle: PhotoMessageCollectionVie
let colors: Colors
let baseStyle: BaseMessageCollectionViewCellDefaultStyle
public init(
bubbleMasks: BubbleMasks = Class.createDefaultBubbleMasks(),
sizes: Sizes = Class.createDefaultSizes(),
colors: Colors = Class.createDefaultColors(),
bubbleMasks: BubbleMasks = PhotoMessageCollectionViewCellDefaultStyle.createDefaultBubbleMasks(),
sizes: Sizes = PhotoMessageCollectionViewCellDefaultStyle.createDefaultSizes(),
colors: Colors = PhotoMessageCollectionViewCellDefaultStyle.createDefaultColors(),
baseStyle: BaseMessageCollectionViewCellDefaultStyle = BaseMessageCollectionViewCellDefaultStyle()) {
self.bubbleMasks = bubbleMasks
self.sizes = sizes
Expand Down
Expand Up @@ -159,8 +159,8 @@ public final class TextBubbleView: UIView, MaximumLayoutWidthSpecificable, Backg
if self.textView.textColor != textColor {
self.textView.textColor = textColor
self.textView.linkTextAttributes = [
NSAttributedStringKey.foregroundColor.rawValue: textColor,
NSAttributedStringKey.underlineStyle.rawValue: NSUnderlineStyle.styleSingle.rawValue
NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue
]
needsToUpdateText = true
}
Expand Down Expand Up @@ -275,8 +275,8 @@ private final class TextBubbleLayoutModel {
private func replicateUITextViewNSTextStorage() -> NSTextStorage {
// See https://github.com/badoo/Chatto/issues/129
return NSTextStorage(string: self.layoutContext.text, attributes: [
NSAttributedStringKey.font: self.layoutContext.font,
NSAttributedStringKey(rawValue: "NSOriginalFont"): self.layoutContext.font
NSAttributedString.Key.font: self.layoutContext.font,
NSAttributedString.Key(rawValue: "NSOriginalFont"): self.layoutContext.font
])
}
}
Expand Down
Expand Up @@ -69,8 +69,8 @@ open class TextMessageCollectionViewCellDefaultStyle: TextMessageCollectionViewC
public let textStyle: TextStyle
public let baseStyle: BaseMessageCollectionViewCellDefaultStyle
public init (
bubbleImages: BubbleImages = Class.createDefaultBubbleImages(),
textStyle: TextStyle = Class.createDefaultTextStyle(),
bubbleImages: BubbleImages = TextMessageCollectionViewCellDefaultStyle.createDefaultBubbleImages(),
textStyle: TextStyle = TextMessageCollectionViewCellDefaultStyle.createDefaultTextStyle(),
baseStyle: BaseMessageCollectionViewCellDefaultStyle = BaseMessageCollectionViewCellDefaultStyle()) {
self.bubbleImages = bubbleImages
self.textStyle = textStyle
Expand Down
2 changes: 1 addition & 1 deletion ChattoAdditions/Source/Common/AnimationUtils.swift
Expand Up @@ -28,7 +28,7 @@ public extension CABasicAnimation {
animation.duration = duration
animation.fromValue = 0
animation.toValue = 1
animation.fillMode = kCAFillModeForwards
animation.fillMode = .forwards
animation.isAdditive = false
return animation
}
Expand Down
2 changes: 1 addition & 1 deletion ChattoAdditions/Source/Input/ChatInputBar.swift
Expand Up @@ -116,7 +116,7 @@ open class ChatInputBar: ReusableXibView {
public var maxCharactersCount: UInt? // nil -> unlimited

private func updateIntrinsicContentSizeAnimated() {
let options: UIViewAnimationOptions = [.beginFromCurrentState, .allowUserInteraction]
let options: UIView.AnimationOptions = [.beginFromCurrentState, .allowUserInteraction]
UIView.animate(withDuration: 0.25, delay: 0, options: options, animations: { () -> Void in
self.invalidateIntrinsicContentSize()
self.layoutIfNeeded()
Expand Down
4 changes: 2 additions & 2 deletions ChattoAdditions/Source/Input/ChatInputBarAppearance.swift
Expand Up @@ -64,9 +64,9 @@ public struct ChatInputBarAppearance {
// Workaround for SR-2223
public struct UIControlStateWrapper: Hashable {

public let controlState: UIControlState
public let controlState: UIControl.State

public init(state: UIControlState) {
public init(state: UIControl.State) {
self.controlState = state
}

Expand Down
8 changes: 4 additions & 4 deletions ChattoAdditions/Source/Input/ChatInputBarPresenter.swift
Expand Up @@ -50,9 +50,9 @@ public class BasicChatInputBarPresenter: NSObject, ChatInputBarPresenter {

self.chatInputBar.presenter = self
self.chatInputBar.inputItems = self.chatInputItems
self.notificationCenter.addObserver(self, selector: #selector(BasicChatInputBarPresenter.keyboardDidChangeFrame), name: NSNotification.Name.UIKeyboardDidChangeFrame, object: nil)
self.notificationCenter.addObserver(self, selector: #selector(BasicChatInputBarPresenter.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
self.notificationCenter.addObserver(self, selector: #selector(BasicChatInputBarPresenter.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
self.notificationCenter.addObserver(self, selector: #selector(BasicChatInputBarPresenter.keyboardDidChangeFrame), name: UIApplication.keyboardDidChangeFrameNotification, object: nil)
self.notificationCenter.addObserver(self, selector: #selector(BasicChatInputBarPresenter.keyboardWillHide), name: UIApplication.keyboardWillHideNotification, object: nil)
self.notificationCenter.addObserver(self, selector: #selector(BasicChatInputBarPresenter.keyboardWillShow), name: UIApplication.keyboardWillShowNotification, object: nil)
}

deinit {
Expand Down Expand Up @@ -114,7 +114,7 @@ public class BasicChatInputBarPresenter: NSObject, ChatInputBarPresenter {
@objc
private func keyboardDidChangeFrame(_ notification: Notification) {
guard self.allowListenToChangeFrameEvents else { return }
guard let value = (notification as NSNotification).userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue else { return }
guard let value = (notification as NSNotification).userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else { return }
self.lastKnownKeyboardHeight = value.cgRectValue.height
}

Expand Down
2 changes: 1 addition & 1 deletion ChattoAdditions/Source/Input/ExpandableTextView.swift
Expand Up @@ -56,7 +56,7 @@ open class ExpandableTextView: UITextView {
}

private func commonInit() {
NotificationCenter.default.addObserver(self, selector: #selector(ExpandableTextView.textDidChange), name: NSNotification.Name.UITextViewTextDidChange, object: self)
NotificationCenter.default.addObserver(self, selector: #selector(ExpandableTextView.textDidChange), name: UITextView.textDidChangeNotification, object: self)
self.configurePlaceholder()
self.updatePlaceholderVisibility()
}
Expand Down
Expand Up @@ -36,7 +36,7 @@ final class DeviceImagePicker: NSObject, ImagePicker, UIImagePickerControllerDel
}

@objc
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
self.delegate?.imagePickerDidFinish(self, mediaInfo: info)
}

Expand Down
Expand Up @@ -25,7 +25,7 @@
import UIKit

public protocol ImagePickerDelegate: class {
func imagePickerDidFinish(_ picker: ImagePicker, mediaInfo: [String: Any])
func imagePickerDidFinish(_ picker: ImagePicker, mediaInfo: [UIImagePickerController.InfoKey: Any])
func imagePickerDidCancel(_ picker: ImagePicker)
}

Expand Down

0 comments on commit bed6a0a

Please sign in to comment.