Skip to content

Commit 68a9d33

Browse files
committed
Update due to swift 3 guidelines
1 parent f1a54f2 commit 68a9d33

12 files changed

+83
-66
lines changed

MenuExample/Controller/ContentViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import UIKit
88

99
class ContentViewController: UIViewController {
10+
1011
var type: ContentType = .Music
1112

12-
@IBOutlet
13-
weak var imageView: UIImageView!
13+
@IBOutlet weak var imageView: UIImageView!
1414

1515
override func viewDidLoad() {
1616
super.viewDidLoad()

MenuExample/Controller/MenuViewController.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import UIKit
88
import SideMenu
99

1010
protocol MenuViewControllerDelegate: class {
11-
func menu(_ menu: MenuViewController, didSelectItemAtIndex index: Int, atPoint point: CGPoint)
11+
12+
func menu(_ menu: MenuViewController, didSelectItemAt index: Int, at point: CGPoint)
1213
func menuDidCancel(_ menu: MenuViewController)
1314
}
1415

1516
class MenuViewController: UITableViewController {
17+
1618
weak var delegate: MenuViewControllerDelegate?
1719
var selectedItem = 0
1820

@@ -22,25 +24,25 @@ class MenuViewController: UITableViewController {
2224
let indexPath = IndexPath(row: selectedItem, section: 0)
2325
tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)
2426
}
25-
2627
}
2728

2829
extension MenuViewController {
29-
@IBAction
30-
fileprivate func dismissMenu() {
30+
31+
@IBAction fileprivate func dismissMenu() {
3132
delegate?.menuDidCancel(self)
3233
}
3334
}
3435

3536
//MARK: Menu protocol
36-
extension MenuViewController: Menu {
37+
extension MenuViewController: Menu {
38+
3739
var menuItems: [UIView] {
3840
return [tableView.tableHeaderView!] + tableView.visibleCells
3941
}
4042
}
4143

42-
// MARK: - UITableViewDelegate
4344
extension MenuViewController {
45+
4446
override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
4547
return indexPath == tableView.indexPathForSelectedRow ? nil : indexPath
4648
}
@@ -49,6 +51,6 @@ extension MenuViewController {
4951
let rect = tableView.rectForRow(at: indexPath)
5052
var point = CGPoint(x: rect.midX, y: rect.midY)
5153
point = tableView.convert(point, to: nil)
52-
delegate?.menu(self, didSelectItemAtIndex: (indexPath as NSIndexPath).row, atPoint:point)
54+
delegate?.menu(self, didSelectItemAt: indexPath.row, at: point)
5355
}
5456
}

MenuExample/Controller/ViewController.swift

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,42 @@ import UIKit
88
import SideMenu
99

1010
class ViewController: UIViewController {
11+
1112
fileprivate var selectedIndex = 0
1213
fileprivate var transitionPoint: CGPoint!
1314
fileprivate var contentType: ContentType = .Music
1415
fileprivate var navigator: UINavigationController!
16+
1517
lazy fileprivate var menuAnimator : MenuTransitionAnimator! = MenuTransitionAnimator(mode: .presentation, shouldPassEventsOutsideMenu: false) { [unowned self] in
1618
self.dismiss(animated: true, completion: nil)
1719
}
20+
1821
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
1922
switch (segue.identifier, segue.destination) {
20-
case (.some("presentMenu"), let menu as MenuViewController):
21-
menu.selectedItem = selectedIndex
22-
menu.delegate = self
23-
menu.transitioningDelegate = self
24-
menu.modalPresentationStyle = .custom
25-
case (.some("embedNavigator"), let navigator as UINavigationController):
26-
self.navigator = navigator
27-
self.navigator.delegate = self
28-
default:
29-
super.prepare(for: segue, sender: sender)
23+
case (.some("presentMenu"), let menu as MenuViewController):
24+
menu.selectedItem = selectedIndex
25+
menu.delegate = self
26+
menu.transitioningDelegate = self
27+
menu.modalPresentationStyle = .custom
28+
case (.some("embedNavigator"), let navigator as UINavigationController):
29+
self.navigator = navigator
30+
self.navigator.delegate = self
31+
default:
32+
super.prepare(for: segue, sender: sender)
3033
}
3134
}
3235
}
3336

3437
extension ViewController: MenuViewControllerDelegate {
35-
func menu(_: MenuViewController, didSelectItemAtIndex index: Int, atPoint point: CGPoint) {
38+
39+
func menu(_: MenuViewController, didSelectItemAt index: Int, at point: CGPoint) {
3640
contentType = !contentType
3741
transitionPoint = point
3842
selectedIndex = index
3943

4044
let content = storyboard!.instantiateViewController(withIdentifier: "Content") as! ContentViewController
4145
content.type = contentType
42-
self.navigator.setViewControllers([content], animated: true)
46+
navigator.setViewControllers([content], animated: true)
4347

4448
DispatchQueue.main.async {
4549
self.dismiss(animated: true, completion: nil)
@@ -52,6 +56,7 @@ extension ViewController: MenuViewControllerDelegate {
5256
}
5357

5458
extension ViewController: UINavigationControllerDelegate {
59+
5560
func navigationController(_: UINavigationController, animationControllerFor _: UINavigationControllerOperation,
5661
from _: UIViewController, to _: UIViewController) -> UIViewControllerAnimatedTransitioning? {
5762

@@ -63,6 +68,7 @@ extension ViewController: UINavigationControllerDelegate {
6368
}
6469

6570
extension ViewController: UIViewControllerTransitioningDelegate {
71+
6672
func animationController(forPresented presented: UIViewController, presenting _: UIViewController,
6773
source _: UIViewController) -> UIViewControllerAnimatedTransitioning? {
6874
return menuAnimator
@@ -71,5 +77,4 @@ extension ViewController: UIViewControllerTransitioningDelegate {
7177
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
7278
return MenuTransitionAnimator(mode: .dismissal)
7379
}
74-
7580
}

MenuExample/Extension/UITableViewCell.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import UIKit
88

99
extension UITableViewCell {
10-
@IBInspectable
11-
var normalBackgroundColor: UIColor? {
10+
11+
@IBInspectable var normalBackgroundColor: UIColor? {
1212
get {
1313
return backgroundView?.backgroundColor
1414
}
@@ -19,8 +19,7 @@ extension UITableViewCell {
1919
}
2020
}
2121

22-
@IBInspectable
23-
var selectedBackgroundColor: UIColor? {
22+
@IBInspectable var selectedBackgroundColor: UIColor? {
2423
get {
2524
return selectedBackgroundView?.backgroundColor
2625
}

MenuExample/Misc/AnimationDelegate.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import QuartzCore
88

99
class AnimationDelegate: NSObject, CAAnimationDelegate {
10+
1011
fileprivate let completion: () -> Void
1112

1213
init(completion: @escaping () -> Void) {

MenuExample/Misc/AppDelegate.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import UIKit
88

99
@UIApplicationMain
1010
class AppDelegate: UIResponder, UIApplicationDelegate {
11+
1112
var window: UIWindow?
1213
}
1314

MenuExample/Misc/CircularRevealAnimator.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ private func SquareAroundCircle(_ center: CGPoint, radius: CGFloat) -> CGRect {
1212
}
1313

1414
class CircularRevealAnimator {
15-
var completion: () -> Void = {}
15+
16+
var completion: (() -> Void)?
1617

1718
fileprivate let layer: CALayer
1819
fileprivate let mask: CAShapeLayer
1920
fileprivate let animation: CABasicAnimation
2021

21-
var duration: CFTimeInterval {
22+
var duration: TimeInterval {
2223
get { return animation.duration }
2324
set(value) { animation.duration = value }
2425
}
@@ -42,7 +43,7 @@ class CircularRevealAnimator {
4243
animation.toValue = endPath
4344
animation.delegate = AnimationDelegate {
4445
layer.mask = nil
45-
self.completion()
46+
self.completion?()
4647
self.animation.delegate = nil
4748
}
4849
}

MenuExample/Misc/CircularRevealTransitionAnimator.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import UIKit
88

99
class CircularRevealTransitionAnimator: NSObject {
10+
1011
fileprivate let duration = 0.5
1112
fileprivate let center: CGPoint
1213

@@ -16,6 +17,7 @@ class CircularRevealTransitionAnimator: NSObject {
1617
}
1718

1819
extension CircularRevealTransitionAnimator: UIViewControllerAnimatedTransitioning {
20+
1921
func animateTransition(using context: UIViewControllerContextTransitioning) {
2022
let frame = context.finalFrame(for: context.viewController(forKey: UITransitionContextViewControllerKey.to)!)
2123

MenuExample/Model/ContentType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ prefix func ! (value: ContentType) -> ContentType {
1818
case .Films:
1919
return .Music
2020
}
21-
}
21+
}

SideMenu/Menu.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
import UIKit
88

9-
@objc
10-
public protocol Menu {
9+
@objc public protocol Menu {
10+
1111
var menuItems: [UIView] {get}
1212
}
1313

0 commit comments

Comments
 (0)