Skip to content

Commit

Permalink
Update to Swift 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkfalcon committed Nov 11, 2018
1 parent c0ea110 commit e23f2c2
Show file tree
Hide file tree
Showing 22 changed files with 266 additions and 98 deletions.
2 changes: 1 addition & 1 deletion CardParts/src/Classes/Card Parts/CardPartBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class CardPartBarView: UIView, CardPartView {
}

override public var intrinsicContentSize: CGSize {
return CGSize(width: UIViewNoIntrinsicMetric, height: 18.0)
return CGSize(width: UIView.noIntrinsicMetric, height: 18.0)
}

fileprivate func updateBarLayer() {
Expand Down
2 changes: 1 addition & 1 deletion CardParts/src/Classes/Card Parts/CardPartButtonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension Reactive where Base: CardPartButtonView {
}
}

public var contentHorizontalAlignment: Binder<UIControlContentHorizontalAlignment>{
public var contentHorizontalAlignment: Binder<UIControl.ContentHorizontalAlignment>{
return Binder(self.base) { (buttonView, contentHorizontalAlignment) -> () in
buttonView.contentHorizontalAlignment = contentHorizontalAlignment
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class CardPartCollectionView : UIView, CardPartView, UICollectionViewDele
}

override public var intrinsicContentSize: CGSize {
return CGSize(width: UIViewNoIntrinsicMetric, height: collectionView.frame.height)
return CGSize(width: UIView.noIntrinsicMetric, height: collectionView.frame.height)
}

override public func updateConstraints() {
Expand Down
2 changes: 1 addition & 1 deletion CardParts/src/Classes/Card Parts/CardPartImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension Reactive where Base: CardPartImageView {
}
}

public var contentMode: Binder<UIViewContentMode>{
public var contentMode: Binder<UIView.ContentMode>{
return Binder(self.base) { (imageView, contentMode) -> () in
imageView.contentMode = contentMode
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CardPartSeparatorView : UIView, CardPartView {
}

override public var intrinsicContentSize: CGSize {
return CGSize(width: UIViewNoIntrinsicMetric, height: 0.5)
return CGSize(width: UIView.noIntrinsicMetric, height: 0.5)
}

}
2 changes: 1 addition & 1 deletion CardParts/src/Classes/Card Parts/CardPartSpacerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class CardPartSpacerView : UIView, CardPartView {
}

override public var intrinsicContentSize: CGSize {
return CGSize(width: UIViewNoIntrinsicMetric, height: height)
return CGSize(width: UIView.noIntrinsicMetric, height: height)
}

}
2 changes: 1 addition & 1 deletion CardParts/src/Classes/Card Parts/CardPartTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class CardPartTableView : UIView, CardPartView, UITableViewDelegate {
}

override public var intrinsicContentSize: CGSize {
return CGSize(width: UIViewNoIntrinsicMetric, height: tableView.contentSize.height)
return CGSize(width: UIView.noIntrinsicMetric, height: tableView.contentSize.height)
}

override public func updateConstraints() {
Expand Down
6 changes: 3 additions & 3 deletions CardParts/src/Classes/Card Parts/CardPartTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class CardPartTableViewCell : UITableViewCell {
private var constraintsAdded = false


override public init(style: UITableViewCellStyle, reuseIdentifier: String?) {
override public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {

leftTitleLabel = UILabel(frame: CGRect.zero)
leftTitleLabel.translatesAutoresizingMaskIntoConstraints = false
Expand Down Expand Up @@ -119,7 +119,7 @@ public class CardPartTableViewCell : UITableViewCell {

super.init(style: style, reuseIdentifier: reuseIdentifier)

separatorInset = UIEdgeInsetsMake(0, 0, 0, 0)
separatorInset = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 0)


for subview in contentView.subviews {
Expand Down Expand Up @@ -289,7 +289,7 @@ public class CardPartTableViewCell : UITableViewCell {
contentView.addConstraint(constraint)

// Right
let nsAttributeType: NSLayoutAttribute = shouldCenterRightLabel ? .left : .right
let nsAttributeType: NSLayoutConstraint.Attribute = shouldCenterRightLabel ? .left : .right
constraint = NSLayoutConstraint(item: rightDescriptionLabel,
attribute: nsAttributeType,
relatedBy: .equal,
Expand Down
2 changes: 1 addition & 1 deletion CardParts/src/Classes/Card Parts/CardPartTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class CardPartTextField : UITextField, CardPartView {

setFormat(format: format)

NotificationCenter.default.addObserver(self, selector: #selector(textChangeNotifcation(notification:)), name: NSNotification.Name.UITextFieldTextDidChange, object: self)
NotificationCenter.default.addObserver(self, selector: #selector(textChangeNotifcation(notification:)), name: UITextField.textDidChangeNotification, object: self)
}

deinit {
Expand Down
6 changes: 3 additions & 3 deletions CardParts/src/Classes/Card Parts/CardPartTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ public class CardPartTextView : UIView, CardPartView {
if let labelText = attributedText {
let mutableAttrText = NSMutableAttributedString(attributedString: labelText)

mutableAttrText.addAttributes([NSAttributedStringKey.paragraphStyle: paragraphStyle],
mutableAttrText.addAttributes([NSAttributedString.Key.paragraphStyle: paragraphStyle],
range: NSRange(location: 0, length: mutableAttrText.length))

label.attributedText = mutableAttrText
} else if let labelText = text {
let mutableAttrText = NSMutableAttributedString(string: labelText, attributes: [NSAttributedStringKey.font: font, NSAttributedStringKey.foregroundColor: textColor])
let mutableAttrText = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: textColor])

mutableAttrText.addAttributes([NSAttributedStringKey.paragraphStyle: paragraphStyle],
mutableAttrText.addAttributes([NSAttributedString.Key.paragraphStyle: paragraphStyle],
range: NSRange(location: 0, length: mutableAttrText.length))
label.attributedText = mutableAttrText
} else {
Expand Down
10 changes: 5 additions & 5 deletions CardParts/src/Classes/Card Parts/CardPartTitleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class CardPartTitleView : UIView, CardPartView {
} else {
button.setImage(UIImage(named: menuButtonImageName, in: Bundle(for: CardPartTitleView.self), compatibleWith: nil), for: .normal)
}
button.addTarget(self, action: #selector(menuButtonTapped), for: UIControlEvents.touchUpInside)
button.addTarget(self, action: #selector(menuButtonTapped), for: UIControl.Event.touchUpInside)
addSubview(button)
}
} else if type == .titleWithActionableButton {
Expand All @@ -94,7 +94,7 @@ public class CardPartTitleView : UIView, CardPartView {
} else {
button.setImage(UIImage(named: menuButtonImageName, in: Bundle(for: CardPartTitleView.self), compatibleWith: nil), for: .normal)
}
button.addTarget(self, action: #selector(actionableMenuTapped), for: UIControlEvents.touchUpInside)
button.addTarget(self, action: #selector(actionableMenuTapped), for: UIControl.Event.touchUpInside)
addSubview(button)
}
}
Expand All @@ -111,10 +111,10 @@ public class CardPartTitleView : UIView, CardPartView {
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[label]|", options: [], metrics: nil, views: ["label" : label]))
if let button = button {
addConstraints([NSLayoutConstraint (item: button,
attribute: NSLayoutAttribute.width,
relatedBy: NSLayoutRelation.equal,
attribute: NSLayoutConstraint.Attribute.width,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: nil,
attribute: NSLayoutAttribute.notAnAttribute,
attribute: NSLayoutConstraint.Attribute.notAnAttribute,
multiplier: 1,
constant: 40)])
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[button]|", options: [], metrics: nil, views: ["button" : button]))
Expand Down
2 changes: 1 addition & 1 deletion CardParts/src/Classes/CardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ open class CardCell : UICollectionViewCell {

override open func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {

let desiredHeight: CGFloat = contentView.systemLayoutSizeFitting(UILayoutFittingCompressedSize).height
let desiredHeight: CGFloat = contentView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height

if currentSize.height != desiredHeight || currentSize != layoutAttributes.size {
let attr = super.preferredLayoutAttributesFitting(layoutAttributes)
Expand Down
4 changes: 2 additions & 2 deletions CardParts/src/Classes/CardPartTableViewCardPartsCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ open class CardPartTableViewCardPartsCell : UITableViewCell {
var stackView : UIStackView
private var cardParts:[CardPartView] = []

override public init(style: UITableViewCellStyle, reuseIdentifier: String?) {
override public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {

stackView = UIStackView()
stackView.translatesAutoresizingMaskIntoConstraints = false
Expand All @@ -28,7 +28,7 @@ open class CardPartTableViewCardPartsCell : UITableViewCell {

super.init(style: style, reuseIdentifier: reuseIdentifier)

separatorInset = UIEdgeInsetsMake(0, 0, 0, 0)
separatorInset = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 0)

for subview in contentView.subviews {
subview.removeFromSuperview()
Expand Down
12 changes: 6 additions & 6 deletions CardParts/src/Classes/CardPartsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ open class CardPartsViewController : UIViewController, CardController {
padding += cardPart.margins.top

if let cardViewController = cardPart.viewController {
addChildViewController(cardViewController)
addChild(cardViewController)
view.addSubview(cardPart.view)
cardViewController.didMove(toParentViewController: self)
cardViewController.didMove(toParent: self)
} else {
view.addSubview(cardPart.view)
}
Expand Down Expand Up @@ -149,9 +149,9 @@ open class CardPartsViewController : UIViewController, CardController {
if let stateData = cardParts[state] {
stateData.cardParts.forEach {
if let cardViewController = $0.viewController {
addChildViewController(cardViewController)
addChild(cardViewController)
view.addSubview($0.view)
cardViewController.didMove(toParentViewController: self)
cardViewController.didMove(toParent: self)
} else {
view.addSubview($0.view)
}
Expand All @@ -164,14 +164,14 @@ open class CardPartsViewController : UIViewController, CardController {
if let stateData = cardParts[state] {
stateData.cardParts.forEach {
if let cardViewController = $0.viewController {
cardViewController.willMove(toParentViewController: nil)
cardViewController.willMove(toParent: nil)
}
}
view.removeConstraints(stateData.constraints)
stateData.cardParts.forEach {
if let cardViewController = $0.viewController {
cardViewController.view.removeFromSuperview()
cardViewController.removeFromParentViewController()
cardViewController.removeFromParent()
} else {
$0.view.removeFromSuperview()
}
Expand Down
30 changes: 15 additions & 15 deletions CardParts/src/Classes/CardsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ open class CardsViewController : UIViewController, UICollectionViewDataSource, U

layout = UICollectionViewFlowLayout()
if #available(iOS 10.0, *) {
layout.estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize
layout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
} else {
layout.estimatedItemSize = CGSize(width: self.view.bounds.size.width, height: 1)
}
Expand Down Expand Up @@ -199,7 +199,7 @@ open class CardsViewController : UIViewController, UICollectionViewDataSource, U

let hasParent = viewController.parent != nil
if !hasParent {
addChildViewController(viewController)
addChild(viewController)
}

cell.cardContentView.addSubview(viewController.view)
Expand All @@ -224,7 +224,7 @@ open class CardsViewController : UIViewController, UICollectionViewDataSource, U
cell.contentView.addSubview(editButton)
}
if !hasParent {
viewController.didMove(toParentViewController: self)
viewController.didMove(toParent: self)
}
}
cell.cardContentView.layoutIfNeeded()
Expand Down Expand Up @@ -311,33 +311,33 @@ extension CardsViewController {

private func listenToKeyboardShowHideNotifications() {
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
notificationCenter.addObserver(self, selector: #selector(keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
notificationCenter.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
notificationCenter.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
}

private func stopListeningToKeyboardShowHideNotifications() {
let notificationCenter = NotificationCenter.default
notificationCenter.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: nil)
notificationCenter.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil)
notificationCenter.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil)
notificationCenter.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
}

@objc open func keyboardWillShow(notification: Notification) {
guard var keyboardRect = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue,
let keyboardCurve = (notification.userInfo?[UIKeyboardAnimationCurveUserInfoKey] as? NSNumber)?.intValue,
let keyboardDuration = (notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue,
guard var keyboardRect = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue,
let keyboardCurve = (notification.userInfo?[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber)?.intValue,
let keyboardDuration = (notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue,
let responder = UIResponder.first as? UIView
else { return }

keyboardRect = self.view.convert(keyboardRect, from: nil)

let scrollViewKeyboardIntersection = collectionView.frame.intersection(keyboardRect)
let newContentInsets = UIEdgeInsetsMake(0, 0, scrollViewKeyboardIntersection.size.height, 0)
let newContentInsets = UIEdgeInsets.init(top: 0, left: 0, bottom: scrollViewKeyboardIntersection.size.height, right: 0)

savedContentInset = collectionView.contentInset

UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(keyboardDuration)
if let animationCurve = UIViewAnimationCurve.init(rawValue: keyboardCurve) {
if let animationCurve = UIView.AnimationCurve.init(rawValue: keyboardCurve) {
UIView.setAnimationCurve(animationCurve)
}
collectionView.contentInset = newContentInsets
Expand Down Expand Up @@ -367,13 +367,13 @@ extension CardsViewController {
}

@objc open func keyboardWillHide(notification: Notification) {
guard let keyboardCurve = (notification.userInfo?[UIKeyboardAnimationCurveUserInfoKey] as? NSNumber)?.intValue,
let keyboardDuration = (notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue
guard let keyboardCurve = (notification.userInfo?[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber)?.intValue,
let keyboardDuration = (notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue
else { return }

UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(keyboardDuration)
if let animationCurve = UIViewAnimationCurve.init(rawValue: keyboardCurve) {
if let animationCurve = UIView.AnimationCurve.init(rawValue: keyboardCurve) {
UIView.setAnimationCurve(animationCurve)
}
collectionView.contentInset = savedContentInset
Expand Down
Loading

0 comments on commit e23f2c2

Please sign in to comment.