Skip to content

Commit

Permalink
Migrate to Swift 5
Browse files Browse the repository at this point in the history
  • Loading branch information
evnaz committed May 10, 2019
1 parent 98c3c10 commit a511e4c
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 71 deletions.
34 changes: 25 additions & 9 deletions Example/SwiftSideMenu.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0830;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = "Evgeny Nazarov";
TargetAttributes = {
5C132582198E2A9A00CA49BE = {
Expand All @@ -209,14 +209,14 @@
};
5C132594198E2A9A00CA49BE = {
CreatedOnToolsVersion = 6.0;
LastSwiftMigration = 0900;
LastSwiftMigration = 1020;
TestTargetID = 5C132582198E2A9A00CA49BE;
};
};
};
buildConfigurationList = 5C13257E198E2A9A00CA49BE /* Build configuration list for PBXProject "SwiftSideMenu" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Expand Down Expand Up @@ -303,18 +303,27 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
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_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -350,18 +359,27 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
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_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -396,7 +414,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "ru.test.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -410,7 +428,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "ru.test.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -430,8 +448,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ru.test.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUNDLE_LOADER)";
};
name = Debug;
Expand All @@ -448,8 +465,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ru.test.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUNDLE_LOADER)";
};
name = Release;
Expand Down
2 changes: 1 addition & 1 deletion Example/SwiftSideMenu/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
35 changes: 11 additions & 24 deletions Example/SwiftSideMenu/MyMenuTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,44 @@
import UIKit

class MyMenuTableViewController: UITableViewController {

private let menuOptionCellId = "Cell"
var selectedMenuItem : Int = 0

override func viewDidLoad() {
super.viewDidLoad()

// Customize apperance of table view
tableView.contentInset = UIEdgeInsetsMake(64.0, 0, 0, 0) //
tableView.contentInset = UIEdgeInsets(top: 64.0, left: 0, bottom: 0, right: 0)
tableView.separatorStyle = .none
tableView.backgroundColor = UIColor.clear
tableView.scrollsToTop = false

// Preserve selection between presentations
self.clearsSelectionOnViewWillAppear = false
clearsSelectionOnViewWillAppear = false

// Preselect a menu option
tableView.selectRow(at: IndexPath(row: selectedMenuItem, section: 0), animated: false, scrollPosition: .middle)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// Return the number of sections.
return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
return 4
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

var cell = tableView.dequeueReusableCell(withIdentifier: "CELL")
var cell = tableView.dequeueReusableCell(withIdentifier: menuOptionCellId)

if (cell == nil) {
cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "CELL")
cell!.backgroundColor = UIColor.clear
cell!.textLabel?.textColor = UIColor.darkGray
cell = UITableViewCell(style:.default, reuseIdentifier: menuOptionCellId)
cell!.backgroundColor = .clear
cell!.textLabel?.textColor = .darkGray
let selectedBackgroundView = UIView(frame: CGRect(x: 0, y: 0, width: cell!.frame.size.width, height: cell!.frame.size.height))
selectedBackgroundView.backgroundColor = UIColor.gray.withAlphaComponent(0.2)
cell!.selectedBackgroundView = selectedBackgroundView
Expand Down Expand Up @@ -93,15 +91,4 @@ class MyMenuTableViewController: UITableViewController {
sideMenuController()?.setContentViewController(destViewController)
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

}
21 changes: 14 additions & 7 deletions Example/SwiftSideMenu/MyNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ class MyNavigationController: ENSideMenuNavigationController {
override func viewDidLoad() {
super.viewDidLoad()

sideMenu = ENSideMenu(sourceView: self.view, menuViewController: MyMenuTableViewController(), menuPosition:.left)
//sideMenu?.delegate = self //optional
sideMenu?.menuWidth = 180.0 // optional, default is 160
//sideMenu?.bouncingEnabled = false
//sideMenu?.allowPanGesture = false
// make navigation bar showing over side menu
view.bringSubview(toFront: navigationBar)
// Create a table view controller
let tableViewController = MyMenuTableViewController()

// Create side menu
sideMenu = ENSideMenu(sourceView: view, menuViewController: tableViewController, menuPosition:.left)

// Set a delegate
sideMenu?.delegate = self

// Configure side menu
sideMenu?.menuWidth = 180.0

// Show navigation bar above side menu
view.bringSubviewToFront(navigationBar)
}

override func didReceiveMemoryWarning() {
Expand Down
18 changes: 0 additions & 18 deletions Example/SwiftSideMenu/ViewController2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@ class ViewController2: UIViewController, ENSideMenuDelegate {

override func viewDidLoad() {
super.viewDidLoad()
//Move next line to viewWillAppear functon if you store your view controllers
self.sideMenuController()?.sideMenu?.delegate = self
// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

// MARK: - ENSideMenu Delegate
Expand All @@ -39,20 +32,9 @@ class ViewController2: UIViewController, ENSideMenuDelegate {
print("sideMenuDidOpen")
}


func sideMenuShouldOpenSideMenu() -> Bool {
print("sideMenuShouldOpenSideMenu")
return true
}

/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/

}
22 changes: 11 additions & 11 deletions Library/ENSideMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ public extension UIViewController {
/**
Changes current state of side menu view.
*/
public func toggleSideMenuView () {
func toggleSideMenuView () {
sideMenuController()?.sideMenu?.toggleMenu()
}
/**
Hides the side menu view.
*/
public func hideSideMenuView () {
func hideSideMenuView () {
sideMenuController()?.sideMenu?.hideSideMenu()
}
/**
Shows the side menu view.
*/
public func showSideMenuView () {
func showSideMenuView () {
sideMenuController()?.sideMenu?.showSideMenu()
}

Expand All @@ -61,7 +61,7 @@ public extension UIViewController {

:returns: BOOL value
*/
public func isSideMenuOpen () -> Bool {
func isSideMenuOpen () -> Bool {
let sieMenuOpen = sideMenuController()?.sideMenu?.isMenuOpen
return sieMenuOpen!
}
Expand All @@ -81,7 +81,7 @@ public extension UIViewController {

:returns: A `UIViewController`responding to `ENSideMenuProtocol` protocol
*/
public func sideMenuController () -> ENSideMenuProtocol? {
func sideMenuController () -> ENSideMenuProtocol? {
var iteration : UIViewController? = parent
if (iteration == nil) {
return topMostController()
Expand Down Expand Up @@ -131,7 +131,7 @@ open class ENSideMenu : NSObject, UIGestureRecognizerDelegate {
}
}
fileprivate var menuPosition:ENSideMenuPosition = .left
fileprivate var blurStyle: UIBlurEffectStyle = .light
fileprivate var blurStyle: UIBlurEffect.Style = .light
/// A Boolean value indicating whether the bouncing effect is enabled. The default value is TRUE.
open var bouncingEnabled :Bool = true
/// The duration of the slide animation. Used only when `bouncingEnabled` is FALSE.
Expand Down Expand Up @@ -159,7 +159,7 @@ open class ENSideMenu : NSObject, UIGestureRecognizerDelegate {

:returns: An initialized `ENSideMenu` object, added to the specified view.
*/
public init(sourceView: UIView, menuPosition: ENSideMenuPosition, blurStyle: UIBlurEffectStyle = .light) {
public init(sourceView: UIView, menuPosition: ENSideMenuPosition, blurStyle: UIBlurEffect.Style = .light) {
super.init()
self.sourceView = sourceView
self.menuPosition = menuPosition
Expand All @@ -176,12 +176,12 @@ open class ENSideMenu : NSObject, UIGestureRecognizerDelegate {
// Add right swipe gesture recognizer
let rightSwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(ENSideMenu.handleGesture(_:)))
rightSwipeGestureRecognizer.delegate = self
rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirection.right
rightSwipeGestureRecognizer.direction = .right

// Add left swipe gesture recognizer
let leftSwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(ENSideMenu.handleGesture(_:)))
leftSwipeGestureRecognizer.delegate = self
leftSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirection.left
leftSwipeGestureRecognizer.direction = .left

if (menuPosition == .left) {
sourceView.addGestureRecognizer(rightSwipeGestureRecognizer)
Expand All @@ -202,7 +202,7 @@ open class ENSideMenu : NSObject, UIGestureRecognizerDelegate {

:returns: An initialized `ENSideMenu` object, added to the specified view, containing the specified menu view controller.
*/
public convenience init(sourceView: UIView, menuViewController: UIViewController, menuPosition: ENSideMenuPosition, blurStyle: UIBlurEffectStyle = .light) {
public convenience init(sourceView: UIView, menuViewController: UIViewController, menuPosition: ENSideMenuPosition, blurStyle: UIBlurEffect.Style = .light) {
self.init(sourceView: sourceView, menuPosition: menuPosition, blurStyle: blurStyle)
self.menuViewController = menuViewController
menuViewController.view.frame = sideMenuContainerView.bounds
Expand Down Expand Up @@ -309,7 +309,7 @@ open class ENSideMenu : NSObject, UIGestureRecognizerDelegate {
to: CGPoint(x: boundaryPointX, y: height))
animator.addBehavior(collisionBehavior)

let pushBehavior = UIPushBehavior(items: [sideMenuContainerView], mode: UIPushBehaviorMode.instantaneous)
let pushBehavior = UIPushBehavior(items: [sideMenuContainerView], mode: .instantaneous)
pushBehavior.magnitude = pushMagnitude
animator.addBehavior(pushBehavior)

Expand Down
2 changes: 1 addition & 1 deletion Library/ENSideMenuNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ open class ENSideMenuNavigationController: UINavigationController, ENSideMenuPro
}

sideMenu = ENSideMenu(sourceView: self.view, menuViewController: menuViewController, menuPosition:.left)
view.bringSubview(toFront: navigationBar)
view.bringSubviewToFront(navigationBar)
}

required public init?(coder aDecoder: NSCoder) {
Expand Down

0 comments on commit a511e4c

Please sign in to comment.