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

Swift3 conversion #48

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
48 changes: 32 additions & 16 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,22 @@
8C30CA4A1C8E71880008B717 /* Hakuba */ = {
isa = PBXGroup;
children = (
8C30CA4C1C8E71880008B717 /* Common.swift */,
8C30CA4B1C8E71880008B717 /* ArrayExt.swift */,
8C30CA4D1C8E71880008B717 /* BumpTracker.swift */,
8CFF14811C9568C9005699CE /* CellType.swift */,
8C30CA4E1C8E71880008B717 /* Cell.swift */,
8C30CA4F1C8E71880008B717 /* CellModel.swift */,
8C5820DA1C984FDD009FB9AE /* HeaderFooterViewType.swift */,
8C30CA501C8E71880008B717 /* HeaderFooterView.swift */,
8C30CA511C8E71880008B717 /* HeaderFooterViewModel.swift */,
8C30CA571C8E71880008B717 /* Section.swift */,
8CFF14811C9568C9005699CE /* CellType.swift */,
8C30CA4C1C8E71880008B717 /* Common.swift */,
8C30CA541C8E71880008B717 /* Hakuba.swift */,
8C30CA521C8E71880008B717 /* Hakuba+Registration.swift */,
8C30CA531C8E71880008B717 /* Hakuba+UIScrollViewDelegate.swift */,
8C30CA551C8E71880008B717 /* HakubaDelegate.swift */,
8C30CA501C8E71880008B717 /* HeaderFooterView.swift */,
8C30CA511C8E71880008B717 /* HeaderFooterViewModel.swift */,
8C5820DA1C984FDD009FB9AE /* HeaderFooterViewType.swift */,
8C30CA561C8E71880008B717 /* Label.swift */,
8C30CA4B1C8E71880008B717 /* ArrayExt.swift */,
8C30CA581C8E71880008B717 /* RangeExt.swift */,
8C30CA571C8E71880008B717 /* Section.swift */,
8C30CA591C8E71880008B717 /* TableViewCellExt.swift */,
8C30CA5A1C8E71880008B717 /* TableViewExt.swift */,
8C30CA5B1C8E71880008B717 /* TableViewHeaderFooterViewExt.swift */,
Expand Down Expand Up @@ -182,20 +182,20 @@
isa = PBXGroup;
children = (
8C60BC5E1C89D4550006CE38 /* AppDelegate.swift */,
8C60BC601C89D4550006CE38 /* ViewController.swift */,
8C5820DC1C9852E3009FB9AE /* HeaderFooterTestViewController.swift */,
8C60BC651C89D4550006CE38 /* Assets.xcassets */,
8C5820DE1C9852F7009FB9AE /* CellTestViewController.swift */,
8C3446801C8E6F97002BC8CD /* ChildViewController.swift */,
8C3446811C8E6F97002BC8CD /* CustomCell.swift */,
8CFF14A51C96758A005699CE /* CustomCellModel.swift */,
8C3446821C8E6F97002BC8CD /* CustomCell.xib */,
8C3446801C8E6F97002BC8CD /* ChildViewController.swift */,
8CFF14A51C96758A005699CE /* CustomCellModel.swift */,
8C5820E01C985625009FB9AE /* CustomHeaderView.swift */,
8C5820E21C98562F009FB9AE /* CustomHeaderViewModel.swift */,
8C5820E41C985640009FB9AE /* CustomHeaderView.xib */,
8C60BC621C89D4550006CE38 /* Main.storyboard */,
8C60BC651C89D4550006CE38 /* Assets.xcassets */,
8C60BC671C89D4550006CE38 /* LaunchScreen.storyboard */,
8C5820E21C98562F009FB9AE /* CustomHeaderViewModel.swift */,
8C5820DC1C9852E3009FB9AE /* HeaderFooterTestViewController.swift */,
8C60BC6A1C89D4550006CE38 /* Info.plist */,
8C60BC671C89D4550006CE38 /* LaunchScreen.storyboard */,
8C60BC621C89D4550006CE38 /* Main.storyboard */,
8C60BC601C89D4550006CE38 /* ViewController.swift */,
);
path = Example;
sourceTree = "<group>";
Expand Down Expand Up @@ -281,17 +281,20 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0810;
TargetAttributes = {
8C60BC5A1C89D4550006CE38 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
8C60BC6E1C89D4550006CE38 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
TestTargetID = 8C60BC5A1C89D4550006CE38;
};
8C60BC791C89D4550006CE38 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
TestTargetID = 8C60BC5A1C89D4550006CE38;
};
};
Expand Down Expand Up @@ -445,8 +448,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -490,8 +495,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -510,6 +517,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -524,6 +532,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nghialv.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -536,6 +545,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nghialv.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -547,6 +557,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nghialv.ExampleTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example";
};
name = Debug;
Expand All @@ -559,6 +570,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nghialv.ExampleTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example";
};
name = Release;
Expand All @@ -567,9 +579,11 @@
isa = XCBuildConfiguration;
buildSettings = {
INFOPLIST_FILE = ExampleUITests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nghialv.ExampleUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_TARGET_NAME = Example;
USES_XCTRUNNER = YES;
};
Expand All @@ -579,9 +593,11 @@
isa = XCBuildConfiguration;
buildSettings = {
INFOPLIST_FILE = ExampleUITests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nghialv.ExampleUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_TARGET_NAME = Example;
USES_XCTRUNNER = YES;
};
Expand Down
22 changes: 9 additions & 13 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,36 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}

func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
func delay(_ delay:Double, closure:@escaping ()->()) {
DispatchQueue.main.asyncAfter(
deadline: DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: closure)
}

28 changes: 14 additions & 14 deletions Example/Example/CellTestViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
import UIKit

enum SectionIndex: Int, SectionIndexType {
case Top
case Center
case top
case center

static let count = 2
}

class CellTestViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
private lazy var hakuba: Hakuba = Hakuba(tableView: self.tableView)
fileprivate lazy var hakuba: Hakuba = Hakuba(tableView: self.tableView)

override func viewWillAppear(animated: Bool) {
override func viewWillAppear(_ animated: Bool) {
hakuba.deselectAllCells(animated: true)
}

override func viewDidLoad() {
super.viewDidLoad()
hakuba.registerCellByNib(CustomCell)
hakuba.registerCellByNib(CustomCell.self)

// Top section

Expand All @@ -39,11 +39,11 @@ class CellTestViewController: UIViewController {
}

hakuba
.reset(SectionIndex)
.reset(SectionIndex.self)
.bump()

let topSection = hakuba[SectionIndex.Top]
let centerSection = hakuba[SectionIndex.Center]
let topSection = hakuba[SectionIndex.top]
let centerSection = hakuba[SectionIndex.center]

topSection
.reset(topCellmodels)
Expand All @@ -67,13 +67,13 @@ class CellTestViewController: UIViewController {
delay(1.5) {
centerSection
.append(centerCellmodels)
.bump(.Left)
.bump(.left)
}

delay(3) {
centerSection
.remove(2...4)
.bump(.Right)
.bump(.right)
}

delay(5) {
Expand All @@ -85,19 +85,19 @@ class CellTestViewController: UIViewController {
delay(7.5) {
topSection
.remove(1)
.bump(.Middle)
.bump(.middle)
}

delay(10) {
topSection
.remove(0)
.bump(.Right)
.bump(.right)
}

delay(12.5) {
topSection
.remove(0)
.bump(.Right)
.bump(.right)
}

delay(15) {
Expand All @@ -109,7 +109,7 @@ class CellTestViewController: UIViewController {

func pushChildViewController() {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("ChildViewController") as! ChildViewController
let vc = storyboard.instantiateViewController(withIdentifier: "ChildViewController") as! ChildViewController
self.navigationController?.pushViewController(vc, animated: true)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Example/Example/CustomCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CustomCell: Cell, CellType {
titleLabel.text = cellmodel.title + "(\(cellmodel.indexPath.section),\(cellmodel.indexPath.row))"
}

override func willDisplay(tableView: UITableView) {
override func willDisplay(_ tableView: UITableView) {
super.willDisplay(tableView)

}
Expand Down
2 changes: 1 addition & 1 deletion Example/Example/CustomCellModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
class CustomCellModel: CellModel {
let title: String

init(title: String, selectionHandler: SelectionHandler) {
init(title: String, selectionHandler: @escaping SelectionHandler) {
self.title = title
super.init(cell: CustomCell.self, selectionHandler: selectionHandler)
}
Expand Down
2 changes: 1 addition & 1 deletion Example/Example/CustomHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class CustomHeaderView: HeaderFooterView, HeaderFooterViewType {
label.text = vm.text
}

override func didChangeFloatingState(isFloating: Bool, section: Int) {
override func didChangeFloatingState(_ isFloating: Bool, section: Int) {
super.didChangeFloatingState(isFloating, section: section)

let title = isFloating ? "F \(section)" : "n \(section)"
Expand Down
10 changes: 5 additions & 5 deletions Example/Example/HeaderFooterTestViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import UIKit

class HeaderFooterTestViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
private lazy var hakuba: Hakuba = Hakuba(tableView: self.tableView)
fileprivate lazy var hakuba: Hakuba = Hakuba(tableView: self.tableView)

override func viewWillAppear(animated: Bool) {
override func viewWillAppear(_ animated: Bool) {
hakuba.deselectAllCells(animated: true)
}

override func viewDidLoad() {
super.viewDidLoad()
hakuba.registerCellByNib(CustomCell)
.registerHeaderFooterByNib(CustomHeaderView)
hakuba.registerCellByNib(CustomCell.self)
.registerHeaderFooterByNib(CustomHeaderView.self)

// Top section

Expand Down Expand Up @@ -65,7 +65,7 @@ class HeaderFooterTestViewController: UIViewController {

func pushChildViewController() {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("ChildViewController") as! ChildViewController
let vc = storyboard.instantiateViewController(withIdentifier: "ChildViewController") as! ChildViewController
self.navigationController?.pushViewController(vc, animated: true)
}
}
10 changes: 5 additions & 5 deletions Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ import UIKit

class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
private lazy var hakuba: Hakuba = Hakuba(tableView: self.tableView)
fileprivate lazy var hakuba: Hakuba = Hakuba(tableView: self.tableView)

override func viewWillAppear(animated: Bool) {
override func viewWillAppear(_ animated: Bool) {
hakuba.deselectAllCells(animated: true)
}

override func viewDidLoad() {
super.viewDidLoad()
hakuba.registerCellByNib(CustomCell)
hakuba.registerCellByNib(CustomCell.self)

let cm1 = CustomCellModel(title: "Test cell") { [weak self] _ in
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("CellTestViewController") as! CellTestViewController
let vc = storyboard.instantiateViewController(withIdentifier: "CellTestViewController") as! CellTestViewController
self?.navigationController?.pushViewController(vc, animated: true)
}


let cm2 = CustomCellModel(title: "Test header footer") { [weak self] _ in
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("HeaderFooterTestViewController") as! HeaderFooterTestViewController
let vc = storyboard.instantiateViewController(withIdentifier: "HeaderFooterTestViewController") as! HeaderFooterTestViewController
self?.navigationController?.pushViewController(vc, animated: true)
}

Expand Down
Loading