Skip to content

Commit

Permalink
Finish Swift 3 conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Jun 14, 2016
1 parent 5997097 commit d8d323b
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 61 deletions.
21 changes: 12 additions & 9 deletions Example/CustomTableViewCell.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import UIKit
import Static

final class CustomTableViewCell: UITableViewCell, CellType {
final class CustomTableViewCell: UITableViewCell, Cell {

// MARK: - Properties

private lazy var centeredLabel: UILabel = {
let label = UILabel()
label.textAlignment = .Center
label.textColor = .whiteColor()
label.textAlignment = .center
label.textColor = .white()
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
Expand All @@ -18,14 +18,17 @@ final class CustomTableViewCell: UITableViewCell, CellType {

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.backgroundColor = .grayColor()
contentView.backgroundColor = .gray()

contentView.addSubview(centeredLabel)

let views = ["centeredLabel": centeredLabel]
var constraints: [NSLayoutConstraint] = NSLayoutConstraint.constraintsWithVisualFormat("|-[centeredLabel]-|", options: [], metrics: nil, views: views)
constraints += NSLayoutConstraint.constraintsWithVisualFormat("V:|-[centeredLabel]-|", options: [], metrics: nil, views: views)
NSLayoutConstraint.activateConstraints(constraints)
NSLayoutConstraint.activate([
centeredLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 8),
centeredLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: 8),
centeredLabel.centerXAnchor.constraint(equalTo: contentView.centerXAnchor),
centeredLabel.leadingAnchor.constraint(greaterThanOrEqualTo: contentView.leadingAnchor, constant: 8),
centeredLabel.trailingAnchor.constraint(lessThanOrEqualTo: contentView.trailingAnchor, constant: -8)
])
}

required init?(coder aDecoder: NSCoder) {
Expand All @@ -35,7 +38,7 @@ final class CustomTableViewCell: UITableViewCell, CellType {

// MARK: - CellType

func configure(row row: Row) {
func configure(row: Row) {
centeredLabel.text = row.text
}
}
4 changes: 2 additions & 2 deletions Example/NibTableViewCell.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import Static

final class NibTableViewCell: UITableViewCell, CellType {
final class NibTableViewCell: UITableViewCell, Cell {

// MARK: - Properties

Expand All @@ -14,7 +14,7 @@ final class NibTableViewCell: UITableViewCell, CellType {
return UINib(nibName: String(self), bundle: nil)
}

func configure(row row: Row) {
func configure(row: Row) {
centeredLabel.text = row.text
}
}
26 changes: 13 additions & 13 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ class ViewController: TableViewController {

private let customAccessory: UIView = {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 32, height: 32))
view.backgroundColor = .redColor()
view.backgroundColor = .red()
return view
}()


// MARK: - Initializers

convenience init() {
self.init(style: .Grouped)
self.init(style: .grouped)
}


Expand All @@ -41,15 +41,15 @@ class ViewController: TableViewController {
], footer: "This is a section footer."),
Section(header: "Accessories", rows: [
Row(text: "None"),
Row(text: "Disclosure Indicator", accessory: .DisclosureIndicator),
Row(text: "Detail Disclosure Button", accessory: .DetailDisclosureButton({ [unowned self] in
Row(text: "Disclosure Indicator", accessory: .disclosureIndicator),
Row(text: "Detail Disclosure Button", accessory: .detailDisclosureButton({ [unowned self] in
self.showAlert(title: "Detail Disclosure Button")
})),
Row(text: "Checkmark", accessory: .Checkmark),
Row(text: "Detail Button", accessory: .DetailButton({ [unowned self] in
Row(text: "Checkmark", accessory: .checkmark),
Row(text: "Detail Button", accessory: .detailButton({ [unowned self] in
self.showAlert(title: "Detail Button")
})),
Row(text: "Custom View", accessory: .View(customAccessory))
Row(text: "Custom View", accessory: .view(customAccessory))
], footer: "Try tapping the ⓘ buttons."),
Section(header: "Selection", rows: [
Row(text: "Tap this row", selection: { [unowned self] in
Expand All @@ -62,10 +62,10 @@ class ViewController: TableViewController {
]),
Section(header: "Editing", rows: [
Row(text: "Swipe this row", editActions: [
Row.EditAction(title: "Warn", backgroundColor: .orangeColor(), selection: { [unowned self] in
Row.EditAction(title: "Warn", backgroundColor: .orange(), selection: { [unowned self] in
self.showAlert(title: "Warned.")
}),
Row.EditAction(title: "Delete", style: .Destructive, selection: { [unowned self] in
Row.EditAction(title: "Delete", style: .destructive, selection: { [unowned self] in
self.showAlert(title: "Deleted.")
})
])
Expand All @@ -76,9 +76,9 @@ class ViewController: TableViewController {

// MARK: - Private

private func showAlert(title title: String? = nil, message: String? = "You tapped it. Good work.", button: String = "Thanks") {
let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: button, style: .Cancel, handler: nil))
presentViewController(alert, animated: true, completion: nil)
private func showAlert(title: String? = nil, message: String? = "You tapped it. Good work.", button: String = "Thanks") {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: button, style: .cancel, handler: nil))
present(alert, animated: true, completion: nil)
}
}
6 changes: 3 additions & 3 deletions Example/WindowController.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import UIKit

@UIApplicationMain class WindowController: UIResponder {
@UIApplicationMain final class WindowController: UIResponder {
var window: UIWindow? = {
let window = UIWindow(frame: UIScreen.mainScreen().bounds)
let window = UIWindow(frame: UIScreen.main().bounds)
window.rootViewController = UINavigationController(rootViewController: ViewController())
return window
}()
}


extension WindowController: UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window?.makeKeyAndVisible()
return true
}
Expand Down
32 changes: 16 additions & 16 deletions Static.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
/* Begin PBXBuildFile section */
21826AAE1B3F51A100AA9641 /* Static.h in Headers */ = {isa = PBXBuildFile; fileRef = 21826AAD1B3F51A100AA9641 /* Static.h */; settings = {ATTRIBUTES = (Public, ); }; };
21826AB51B3F51A100AA9641 /* Static.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21826AAA1B3F51A100AA9641 /* Static.framework */; };
21826AC91B3F51D000AA9641 /* ButtonCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21826AC41B3F51D000AA9641 /* ButtonCell.swift */; };
21826ACA1B3F51D000AA9641 /* Row.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21826AC51B3F51D000AA9641 /* Row.swift */; };
21826ACB1B3F51D000AA9641 /* Section.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21826AC61B3F51D000AA9641 /* Section.swift */; };
21826ACC1B3F51D000AA9641 /* DataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21826AC71B3F51D000AA9641 /* DataSource.swift */; };
21826ACD1B3F51D000AA9641 /* Value1Cell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21826AC81B3F51D000AA9641 /* Value1Cell.swift */; };
21826ACF1B3F534000AA9641 /* Value2Cell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21826ACE1B3F534000AA9641 /* Value2Cell.swift */; };
21826AD11B3F535A00AA9641 /* SubtitleCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21826AD01B3F535A00AA9641 /* SubtitleCell.swift */; };
21F219601D10B784001EC0F5 /* CellType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36799F981B41C857009A9D16 /* CellType.swift */; };
21F219611D10B7A9001EC0F5 /* Value1Cell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21826AC81B3F51D000AA9641 /* Value1Cell.swift */; };
21F219621D10B7B9001EC0F5 /* Value2Cell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21826ACE1B3F534000AA9641 /* Value2Cell.swift */; };
21F219631D10B7B9001EC0F5 /* SubtitleCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21826AD01B3F535A00AA9641 /* SubtitleCell.swift */; };
21F219641D10B7B9001EC0F5 /* ButtonCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21826AC41B3F51D000AA9641 /* ButtonCell.swift */; };
21F219671D10B7CF001EC0F5 /* Section.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21826AC61B3F51D000AA9641 /* Section.swift */; };
21F219681D10B895001EC0F5 /* DataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21826AC71B3F51D000AA9641 /* DataSource.swift */; };
21F219691D10B8E1001EC0F5 /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C8FE9A1B4EECF30004DA5B /* TableViewController.swift */; };
363129C71B5035520024E339 /* Static.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21826AAA1B3F51A100AA9641 /* Static.framework */; };
363129C91B50355E0024E339 /* Static.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 21826AAA1B3F51A100AA9641 /* Static.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
366AB2F31B4EE1A7002C4717 /* RowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 366AB2EF1B4EE1A7002C4717 /* RowTests.swift */; };
Expand All @@ -25,8 +27,6 @@
36748D541B5034EC0046F207 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36748D531B5034EC0046F207 /* ViewController.swift */; };
36748D591B5034EC0046F207 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 36748D581B5034EC0046F207 /* Assets.xcassets */; };
36748D5C1B5034EC0046F207 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 36748D5A1B5034EC0046F207 /* LaunchScreen.storyboard */; };
36799F991B41C857009A9D16 /* CellType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36799F981B41C857009A9D16 /* CellType.swift */; };
36C8FE9B1B4EECF30004DA5B /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C8FE9A1B4EECF30004DA5B /* TableViewController.swift */; };
39DC804A1BD96BB0001F04CD /* NibTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39DC80491BD96BB0001F04CD /* NibTableViewCell.swift */; };
A706253D1BC81C1400E471EF /* CustomTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A706253B1BC81C1400E471EF /* CustomTableViewCell.swift */; };
A706253E1BC81C1400E471EF /* NibTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = A706253C1BC81C1400E471EF /* NibTableViewCell.xib */; };
Expand Down Expand Up @@ -336,15 +336,15 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
21826ACB1B3F51D000AA9641 /* Section.swift in Sources */,
21826ACC1B3F51D000AA9641 /* DataSource.swift in Sources */,
21F219631D10B7B9001EC0F5 /* SubtitleCell.swift in Sources */,
21F219611D10B7A9001EC0F5 /* Value1Cell.swift in Sources */,
21826ACA1B3F51D000AA9641 /* Row.swift in Sources */,
21826AC91B3F51D000AA9641 /* ButtonCell.swift in Sources */,
21826ACF1B3F534000AA9641 /* Value2Cell.swift in Sources */,
36799F991B41C857009A9D16 /* CellType.swift in Sources */,
21826AD11B3F535A00AA9641 /* SubtitleCell.swift in Sources */,
36C8FE9B1B4EECF30004DA5B /* TableViewController.swift in Sources */,
21826ACD1B3F51D000AA9641 /* Value1Cell.swift in Sources */,
21F219671D10B7CF001EC0F5 /* Section.swift in Sources */,
21F219621D10B7B9001EC0F5 /* Value2Cell.swift in Sources */,
21F219601D10B784001EC0F5 /* CellType.swift in Sources */,
21F219681D10B895001EC0F5 /* DataSource.swift in Sources */,
21F219691D10B8E1001EC0F5 /* TableViewController.swift in Sources */,
21F219641D10B7B9001EC0F5 /* ButtonCell.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion Static/ButtonCell.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

public class ButtonCell: UITableViewCell, CellType {
public class ButtonCell: UITableViewCell, Cell {

// MARK: - Initializers

Expand Down
6 changes: 3 additions & 3 deletions Static/CellType.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import UIKit

public protocol CellType: class {
public protocol Cell: class {
static func description() -> String
static func nib() -> UINib?

func configure(row: Row)
}

extension CellType {
extension Cell {
public static func nib() -> UINib? {
return nil
}
}

extension CellType where Self: UITableViewCell {
extension Cell where Self: UITableViewCell {
public func configure(row: Row) {
textLabel?.text = row.text
detailTextLabel?.text = row.detailText
Expand Down
10 changes: 5 additions & 5 deletions Static/DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ extension DataSource: UITableViewDataSource {
if let row = rowForIndexPath(indexPath: indexPath) {
let tableCell = tableView.dequeueReusableCell(withIdentifier: row.cellIdentifier, for: indexPath)

if let cell = tableCell as? CellType {
if let cell = tableCell as? Cell {
cell.configure(row: row)
}

Expand All @@ -196,23 +196,23 @@ extension DataSource: UITableViewDataSource {
}

public func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sectionForIndex(index: section)?.header?.title
return sectionForIndex(index: section)?.header?._title
}

public func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return sectionForIndex(index: section)?.header?.view
return sectionForIndex(index: section)?.header?._view
}

public func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return sectionForIndex(index: section)?.header?.viewHeight ?? UITableViewAutomaticDimension
}

public func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
return sectionForIndex(index: section)?.footer?.title
return sectionForIndex(index: section)?.footer?._title
}

public func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return sectionForIndex(index: section)?.footer?.view
return sectionForIndex(index: section)?.footer?._view
}

public func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
Expand Down
4 changes: 2 additions & 2 deletions Static/Row.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public struct Row: Hashable, Equatable {
public var selection: Selection?

/// View to be used for the row.
public var cellClass: CellType.Type
public var cellClass: Cell.Type

/// Additional information for the row.
public var context: Context?
Expand Down Expand Up @@ -134,7 +134,7 @@ public struct Row: Hashable, Equatable {
// MARK: - Initializers

public init(text: String? = nil, detailText: String? = nil, selection: Selection? = nil,
image: UIImage? = nil, accessory: Accessory = .none, cellClass: CellType.Type? = nil, context: Context? = nil, editActions: [EditAction] = [], uuid: String = UUID().uuidString) {
image: UIImage? = nil, accessory: Accessory = .none, cellClass: Cell.Type? = nil, context: Context? = nil, editActions: [EditAction] = [], uuid: String = UUID().uuidString) {

self.uuid = uuid
self.text = text
Expand Down
8 changes: 4 additions & 4 deletions Static/Section.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ public struct Section: Hashable, Equatable {
/// Custom view for the header or footer. The height will be the view's `bounds.height`.
case view(UIView)

public var title: String? {
var _title: String? {
switch self {
case .title(let extremityTitle): return extremityTitle
default: return nil
}
}

public var view: UIView? {
var _view: UIView? {
switch self {
case .view(let extremityView): return extremityView
default: return nil
}
}

public var viewHeight: CGFloat? {
return view?.bounds.height
var viewHeight: CGFloat? {
return _view?.bounds.height
}
}

Expand Down
2 changes: 1 addition & 1 deletion Static/SubtitleCell.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

public class SubtitleCell: UITableViewCell, CellType {
public class SubtitleCell: UITableViewCell, Cell {
public override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
}
Expand Down
2 changes: 1 addition & 1 deletion Static/Value1Cell.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

public class Value1Cell: UITableViewCell, CellType {
public class Value1Cell: UITableViewCell, Cell {
public override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: .value1, reuseIdentifier: reuseIdentifier)
}
Expand Down
2 changes: 1 addition & 1 deletion Static/Value2Cell.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

public class Value2Cell: UITableViewCell, CellType {
public class Value2Cell: UITableViewCell, Cell {
public override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: .value2, reuseIdentifier: reuseIdentifier)
}
Expand Down

0 comments on commit d8d323b

Please sign in to comment.