Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to Swift 3.0 #11

Merged
merged 1 commit into from
Dec 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions CalendarExample/CalendarPagingCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import Parchment

class CalendarPagingCell: PagingCell {

private var theme: PagingTheme?
fileprivate var theme: PagingTheme?

lazy var dateLabel: UILabel = {
let dateLabel = UILabel(frame: .zero)
dateLabel.font = UIFont.systemFontOfSize(20)
dateLabel.font = UIFont.systemFont(ofSize: 20)
return dateLabel
}()

lazy var weekdayLabel: UILabel = {
let weekdayLabel = UILabel(frame: .zero)
weekdayLabel.font = UIFont.systemFontOfSize(12)
weekdayLabel.font = UIFont.systemFont(ofSize: 12)
return weekdayLabel
}()

Expand All @@ -33,7 +33,7 @@ class CalendarPagingCell: PagingCell {
}
}

private func configure() {
fileprivate func configure() {
addSubview(dateLabel)
addSubview(weekdayLabel)

Expand All @@ -42,37 +42,37 @@ class CalendarPagingCell: PagingCell {

let verticalDateLabelContraint = NSLayoutConstraint(
item: dateLabel,
attribute: .CenterY,
relatedBy: .Equal,
attribute: .centerY,
relatedBy: .equal,
toItem: self,
attribute: .CenterY,
attribute: .centerY,
multiplier: 1.0,
constant: -9)

let horizontalDateLabelContraint = NSLayoutConstraint(
item: dateLabel,
attribute: .CenterX,
relatedBy: .Equal,
attribute: .centerX,
relatedBy: .equal,
toItem: self,
attribute: .CenterX,
attribute: .centerX,
multiplier: 1.0,
constant: 0)

let verticalWeekdayLabelContraint = NSLayoutConstraint(
item: weekdayLabel,
attribute: .CenterY,
relatedBy: .Equal,
attribute: .centerY,
relatedBy: .equal,
toItem: self,
attribute: .CenterY,
attribute: .centerY,
multiplier: 1.0,
constant: 12)

let horizontalWeekdayLabelContraint = NSLayoutConstraint(
item: weekdayLabel,
attribute: .CenterX,
relatedBy: .Equal,
attribute: .centerX,
relatedBy: .equal,
toItem: self,
attribute: .CenterX,
attribute: .centerX,
multiplier: 1.0,
constant: 0)

Expand All @@ -84,7 +84,7 @@ class CalendarPagingCell: PagingCell {
])
}

private func updateSelectedState() {
fileprivate func updateSelectedState() {
guard let theme = theme else { return }
if selected {
dateLabel.textColor = theme.selectedTextColor
Expand All @@ -95,7 +95,7 @@ class CalendarPagingCell: PagingCell {
}
}

override func setPagingItem(pagingItem: PagingItem, theme: PagingTheme) {
override func setPagingItem(_ pagingItem: PagingItem, theme: PagingTheme) {
let calendarItem = pagingItem as! CalendarItem
dateLabel.text = DateFormatters.dateFormatter.stringFromDate(calendarItem.date)
weekdayLabel.text = DateFormatters.weekdayFormatter.stringFromDate(calendarItem.date)
Expand Down
10 changes: 5 additions & 5 deletions CalendarExample/CalendarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import UIKit

class CalendarViewController: UIViewController {

init(date: NSDate) {
init(date: Date) {
super.init(nibName: nil, bundle: nil)

let label = UILabel(frame: .zero)
label.font = UIFont.systemFontOfSize(50, weight: UIFontWeightThin)
label.font = UIFont.systemFont(ofSize: 50, weight: UIFontWeightThin)
label.textColor = UIColor(red: 95/255, green: 102/255, blue: 108/255, alpha: 1)
label.text = DateFormatters.shortDateFormatter.stringFromDate(date)
label.text = DateFormatters.shortDateFormatter.string(from: date)
label.sizeToFit()

view.addSubview(label)
view.constrainCentered(label)
view.backgroundColor = .whiteColor()
view.backgroundColor = .white
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

}
}
16 changes: 8 additions & 8 deletions CalendarExample/DateFormatters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import Foundation

struct DateFormatters {

static var shortDateFormatter: NSDateFormatter = {
let dateFormatter = NSDateFormatter()
dateFormatter.timeStyle = .NoStyle
dateFormatter.dateStyle = .ShortStyle
static var shortDateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.timeStyle = .none
dateFormatter.dateStyle = .short
return dateFormatter
}()

static var dateFormatter: NSDateFormatter = {
let dateFormatter = NSDateFormatter()
static var dateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "d"
return dateFormatter
}()

static var weekdayFormatter: NSDateFormatter = {
let dateFormatter = NSDateFormatter()
static var weekdayFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEE"
return dateFormatter
}()
Expand Down
52 changes: 26 additions & 26 deletions CalendarExample/UIView+constraints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,43 @@ import UIKit

extension UIView {

func constrainCentered(subview: UIView) {
func constrainCentered(_ subview: UIView) {

subview.translatesAutoresizingMaskIntoConstraints = false

let verticalContraint = NSLayoutConstraint(
item: subview,
attribute: .CenterY,
relatedBy: .Equal,
attribute: .centerY,
relatedBy: .equal,
toItem: self,
attribute: .CenterY,
attribute: .centerY,
multiplier: 1.0,
constant: 0)

let horizontalContraint = NSLayoutConstraint(
item: subview,
attribute: .CenterX,
relatedBy: .Equal,
attribute: .centerX,
relatedBy: .equal,
toItem: self,
attribute: .CenterX,
attribute: .centerX,
multiplier: 1.0,
constant: 0)

let heightContraint = NSLayoutConstraint(
item: subview,
attribute: .Height,
relatedBy: .Equal,
attribute: .height,
relatedBy: .equal,
toItem: nil,
attribute: .NotAnAttribute,
attribute: .notAnAttribute,
multiplier: 1.0,
constant: subview.frame.height)

let widthContraint = NSLayoutConstraint(
item: subview,
attribute: .Width,
relatedBy: .Equal,
attribute: .width,
relatedBy: .equal,
toItem: nil,
attribute: .NotAnAttribute,
attribute: .notAnAttribute,
multiplier: 1.0,
constant: subview.frame.width)

Expand All @@ -50,43 +50,43 @@ extension UIView {

}

func constrainToEdges(subview: UIView) {
func constrainToEdges(_ subview: UIView) {

subview.translatesAutoresizingMaskIntoConstraints = false

let topContraint = NSLayoutConstraint(
item: subview,
attribute: .Top,
relatedBy: .Equal,
attribute: .top,
relatedBy: .equal,
toItem: self,
attribute: .Top,
attribute: .top,
multiplier: 1.0,
constant: 0)

let bottomConstraint = NSLayoutConstraint(
item: subview,
attribute: .Bottom,
relatedBy: .Equal,
attribute: .bottom,
relatedBy: .equal,
toItem: self,
attribute: .Bottom,
attribute: .bottom,
multiplier: 1.0,
constant: 0)

let leadingContraint = NSLayoutConstraint(
item: subview,
attribute: .Leading,
relatedBy: .Equal,
attribute: .leading,
relatedBy: .equal,
toItem: self,
attribute: .Leading,
attribute: .leading,
multiplier: 1.0,
constant: 0)

let trailingContraint = NSLayoutConstraint(
item: subview,
attribute: .Trailing,
relatedBy: .Equal,
attribute: .trailing,
relatedBy: .equal,
toItem: self,
attribute: .Trailing,
attribute: .trailing,
multiplier: 1.0,
constant: 0)

Expand Down
18 changes: 9 additions & 9 deletions CalendarExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Parchment
// need to make sure it conforms to Equatable,
// since that is required by PagingViewController
struct CalendarItem: PagingItem, Equatable {
let date: NSDate
let date: Date
}

func ==(lhs: CalendarItem, rhs: CalendarItem) -> Bool {
Expand Down Expand Up @@ -55,10 +55,10 @@ class ViewController: UIViewController {
pagingViewController.dataSource = self
}

override func viewDidAppear(animated: Bool) {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// Set the current date as the selected paging item
pagingViewController.selectPagingItem(CalendarItem(date: NSDate()))
pagingViewController.selectPagingItem(CalendarItem(date: Date()))
}

}
Expand All @@ -73,18 +73,18 @@ class ViewController: UIViewController {

extension ViewController: PagingViewControllerDataSource {

func pagingViewController<T>(pagingViewController: PagingViewController<T>, viewControllerForPagingItem pagingItem: T) -> UIViewController {
let calendarItem = pagingItem as! CalendarItem
func pagingViewController<T>(_ pagingViewController: PagingViewController<T>, viewControllerForPagingItem pagingItem: T) -> UIViewController {
let calendarItem = pagingItem
return CalendarViewController(date: calendarItem.date)
}

func pagingViewController<T>(pagingViewController: PagingViewController<T>, pagingItemBeforePagingItem pagingItem: T) -> T? {
let calendarItem = pagingItem as! CalendarItem
func pagingViewController<T>(_ pagingViewController: PagingViewController<T>, pagingItemBeforePagingItem pagingItem: T) -> T? {
let calendarItem = pagingItem
return CalendarItem(date: calendarItem.date.dateByAddingTimeInterval(-86400)) as? T
}

func pagingViewController<T>(pagingViewController: PagingViewController<T>, pagingItemAfterPagingItem pagingItem: T) -> T? {
let calendarItem = pagingItem as! CalendarItem
func pagingViewController<T>(_ pagingViewController: PagingViewController<T>, pagingItemAfterPagingItem pagingItem: T) -> T? {
let calendarItem = pagingItem
return CalendarItem(date: calendarItem.date.dateByAddingTimeInterval(86400)) as? T
}

Expand Down
4 changes: 2 additions & 2 deletions DelegateExample/CityViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ class CityViewController: UIViewController {
self.title = title

let label = UILabel(frame: .zero)
label.font = UIFont.systemFontOfSize(50, weight: UIFontWeightThin)
label.font = UIFont.systemFont(ofSize: 50, weight: UIFontWeightThin)
label.textColor = UIColor(red: 95/255, green: 102/255, blue: 108/255, alpha: 1)
label.text = title
label.sizeToFit()

view.addSubview(label)
view.constrainCentered(label)
view.backgroundColor = .whiteColor()
view.backgroundColor = .white
}

required init?(coder: NSCoder) {
Expand Down
Loading