From 32cd50993908e42f31a6a5799807bea306b68327 Mon Sep 17 00:00:00 2001 From: Michael Buxton Date: Sun, 25 Dec 2016 11:21:10 +0000 Subject: [PATCH] Update example project for Swift 3 (#376) --- Example-iOS/AppDelegate.swift | 17 +++---- Example-iOS/ListViewController.swift | 25 +++++---- .../demos/BasicUIScrollViewController.swift | 28 +++++----- .../demos/SimpleLayoutViewController.swift | 51 +++++++++---------- 4 files changed, 59 insertions(+), 62 deletions(-) diff --git a/Example-iOS/AppDelegate.swift b/Example-iOS/AppDelegate.swift index d4053cc..9f89af6 100644 --- a/Example-iOS/AppDelegate.swift +++ b/Example-iOS/AppDelegate.swift @@ -13,19 +13,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - - self.window = UIWindow(frame: UIScreen.mainScreen().bounds) - + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + + self.window = UIWindow(frame: UIScreen.main.bounds) + let listViewController:ListViewController = ListViewController() let navigationController:UINavigationController = UINavigationController(rootViewController: listViewController); - + self.window!.rootViewController = navigationController; - - self.window!.backgroundColor = UIColor.whiteColor() + + self.window!.backgroundColor = UIColor.white self.window!.makeKeyAndVisible() return true } -} - +} \ No newline at end of file diff --git a/Example-iOS/ListViewController.swift b/Example-iOS/ListViewController.swift index 5fccd7a..5b5082b 100644 --- a/Example-iOS/ListViewController.swift +++ b/Example-iOS/ListViewController.swift @@ -13,35 +13,34 @@ class ListViewController: UITableViewController { let kCellIdentifier = "CellIdentifier" let demos = ["Simple Layout", "Basic UIScrollView"] - + override func viewDidLoad() { super.viewDidLoad() self.title = "SnapKit iOS Demos" - self.tableView?.registerClass(UITableViewCell.self, forCellReuseIdentifier: kCellIdentifier) + self.tableView?.register(UITableViewCell.self, forCellReuseIdentifier: kCellIdentifier) } - - override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier)! as UITableViewCell + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return demos.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: kCellIdentifier)! as UITableViewCell cell.textLabel?.text = demos[indexPath.row] return cell } - override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return demos.count - } - - override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if indexPath.row == 0 { let viewController = SimpleLayoutViewController() navigationController?.pushViewController(viewController, animated: true) } else if indexPath.row == 1 { - let viewController = BasicUIScrollViewController() + let viewController = ViewController() navigationController?.pushViewController(viewController, animated: true) } } -} - +} \ No newline at end of file diff --git a/Example-iOS/demos/BasicUIScrollViewController.swift b/Example-iOS/demos/BasicUIScrollViewController.swift index d9f559f..d7cd91a 100644 --- a/Example-iOS/demos/BasicUIScrollViewController.swift +++ b/Example-iOS/demos/BasicUIScrollViewController.swift @@ -9,7 +9,7 @@ import UIKit class BasicUIScrollViewController: UIViewController { - + var didSetupConstraints = false let scrollView = UIScrollView() @@ -17,22 +17,22 @@ class BasicUIScrollViewController: UIViewController { let label: UILabel = { let label = UILabel() - label.backgroundColor = .blueColor() + label.backgroundColor = .blue label.numberOfLines = 0 - label.lineBreakMode = .ByClipping - label.textColor = .whiteColor() + label.lineBreakMode = .byClipping + label.textColor = .white label.text = NSLocalizedString("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", comment: "") return label }() - + override func viewDidLoad() { super.viewDidLoad() - - view.backgroundColor = UIColor.whiteColor() + + view.backgroundColor = UIColor.white view.addSubview(scrollView) - contentView.backgroundColor = UIColor.lightGrayColor() + contentView.backgroundColor = UIColor.lightGray scrollView.addSubview(contentView) contentView.addSubview(label) @@ -43,16 +43,16 @@ class BasicUIScrollViewController: UIViewController { if (!didSetupConstraints) { - scrollView.snp_makeConstraints { make in - make.edges.equalTo(view).inset(UIEdgeInsetsZero) + scrollView.snp.makeConstraints { make in + make.edges.equalTo(view).inset(UIEdgeInsets.zero) } - contentView.snp_makeConstraints { make in - make.edges.equalTo(scrollView).inset(UIEdgeInsetsZero) + contentView.snp.makeConstraints { make in + make.edges.equalTo(scrollView).inset(UIEdgeInsets.zero) make.width.equalTo(scrollView) } - label.snp_makeConstraints { make in + label.snp.makeConstraints { make in make.top.equalTo(contentView).inset(20) make.leading.equalTo(contentView).inset(20) make.trailing.equalTo(contentView).inset(20) @@ -64,4 +64,4 @@ class BasicUIScrollViewController: UIViewController { super.updateViewConstraints() } -} +} \ No newline at end of file diff --git a/Example-iOS/demos/SimpleLayoutViewController.swift b/Example-iOS/demos/SimpleLayoutViewController.swift index d107b62..78eaccb 100644 --- a/Example-iOS/demos/SimpleLayoutViewController.swift +++ b/Example-iOS/demos/SimpleLayoutViewController.swift @@ -14,38 +14,38 @@ class SimpleLayoutViewController: UIViewController { let blackView: UIView = { let view = UIView() - view.backgroundColor = .blackColor() + view.backgroundColor = .black return view }() let redView: UIView = { let view = UIView() - view.backgroundColor = .redColor() + view.backgroundColor = .red return view }() let yellowView: UIView = { let view = UIView() - view.backgroundColor = .yellowColor() + view.backgroundColor = .yellow return view }() let blueView: UIView = { let view = UIView() - view.backgroundColor = .blueColor() + view.backgroundColor = .blue return view }() let greenView: UIView = { let view = UIView() - view.backgroundColor = .greenColor() + view.backgroundColor = .green return view }() override func viewDidLoad() { super.viewDidLoad() - view.backgroundColor = UIColor.whiteColor() + view.backgroundColor = UIColor.white view.addSubview(blackView) view.addSubview(redView) @@ -60,33 +60,33 @@ class SimpleLayoutViewController: UIViewController { if (!didSetupConstraints) { - blackView.snp_makeConstraints { make in + blackView.snp.makeConstraints { make in make.center.equalTo(view) - make.size.equalTo(CGSizeMake(100.0, 100.0)) + make.size.equalTo(CGSize(width: 100, height: 100)) } - redView.snp_makeConstraints { make in - make.top.equalTo(blackView.snp_bottom).offset(20.0) - make.right.equalTo(blackView.snp_left).offset(-20.0) - make.size.equalTo(CGSizeMake(100.0, 100.0)) + redView.snp.makeConstraints { make in + make.top.equalTo(blackView.snp.bottom).offset(20.0) + make.right.equalTo(blackView.snp.left).offset(-20.0) + make.size.equalTo(CGSize(width: 100, height: 100)) } - yellowView.snp_makeConstraints { make in - make.top.equalTo(blackView.snp_bottom).offset(20.0) - make.left.equalTo(blackView.snp_right).offset(20.0) - make.size.equalTo(CGSizeMake(100.0, 100.0)) + yellowView.snp.makeConstraints { make in + make.top.equalTo(blackView.snp.bottom).offset(20.0) + make.left.equalTo(blackView.snp.right).offset(20.0) + make.size.equalTo(CGSize(width: 100, height: 100)) } - blueView.snp_makeConstraints { make in - make.bottom.equalTo(blackView.snp_top).offset(-20.0) - make.left.equalTo(blackView.snp_right).offset(20.0) - make.size.equalTo(CGSizeMake(100.0, 100.0)) + blueView.snp.makeConstraints { make in + make.bottom.equalTo(blackView.snp.top).offset(-20.0) + make.left.equalTo(blackView.snp.right).offset(20.0) + make.size.equalTo(CGSize(width: 100, height: 100)) } - greenView.snp_makeConstraints { make in - make.bottom.equalTo(blackView.snp_top).offset(-20.0) - make.right.equalTo(blackView.snp_left).offset(-20.0) - make.size.equalTo(CGSizeMake(100.0, 100.0)) + greenView.snp.makeConstraints { make in + make.bottom.equalTo(blackView.snp.top).offset(-20.0) + make.right.equalTo(blackView.snp.left).offset(-20.0) + make.size.equalTo(CGSize(width: 100, height: 100)) } didSetupConstraints = true @@ -94,5 +94,4 @@ class SimpleLayoutViewController: UIViewController { super.updateViewConstraints() } - -} +} \ No newline at end of file