Skip to content

Commit

Permalink
Convert the files used in the sample to Swift 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tasaka-kazunobu committed Sep 14, 2015
1 parent 3075a67 commit ad71bcb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
2 changes: 2 additions & 0 deletions SlideMenuControllerSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@
C539E6391A315E87003B7CC7 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0610;
ORGANIZATIONNAME = "Yuji Hato";
TargetAttributes = {
Expand Down
26 changes: 18 additions & 8 deletions SlideMenuControllerSwift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
private func createMenuView() {

// create viewController code...
var storyboard = UIStoryboard(name: "Main", bundle: nil)
let storyboard = UIStoryboard(name: "Main", bundle: nil)

let mainViewController = storyboard.instantiateViewControllerWithIdentifier("MainViewController") as! MainViewController
let leftViewController = storyboard.instantiateViewControllerWithIdentifier("LeftViewController") as! LeftViewController
Expand Down Expand Up @@ -70,7 +70,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
lazy var applicationDocumentsDirectory: NSURL = {
// The directory the application uses to store the Core Data store file. This code uses a directory named "dekatotoro.test11" in the application's documents Application Support directory.
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
return urls[urls.count-1] as! NSURL
return urls[urls.count-1]
}()

lazy var managedObjectModel: NSManagedObjectModel = {
Expand All @@ -86,7 +86,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("test11.sqlite")
var error: NSError? = nil
var failureReason = "There was an error creating or loading the application's saved data."
if coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil, error: &error) == nil {
do {
try coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil)
} catch var error1 as NSError {
error = error1
coordinator = nil
// Report any error we got.
var dict = [String: AnyObject]()
Expand All @@ -98,6 +101,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog("Unresolved error \(error), \(error!.userInfo)")
abort()
} catch {
fatalError()
}

return coordinator
Expand All @@ -119,11 +124,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func saveContext () {
if let moc = self.managedObjectContext {
var error: NSError? = nil
if moc.hasChanges && !moc.save(&error) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog("Unresolved error \(error), \(error!.userInfo)")
abort()
if moc.hasChanges {
do {
try moc.save()
} catch let error1 as NSError {
error = error1
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog("Unresolved error \(error), \(error!.userInfo)")
abort()
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion SlideMenuControllerSwift/BaseTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
public class BaseTableViewCell : UITableViewCell {
class var identifier: String { return String.className(self) }

public required init(coder aDecoder: NSCoder) {
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
Expand Down
4 changes: 2 additions & 2 deletions SlideMenuControllerSwift/LeftViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ class LeftViewController : UIViewController, LeftMenuProtocol {
var goViewController: UIViewController!
var nonMenuViewController: UIViewController!

required init(coder aDecoder: NSCoder) {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

override func viewDidLoad() {
super.viewDidLoad()
self.tableView.separatorColor = UIColor(red: 224/255, green: 224/255, blue: 224/255, alpha: 1.0)

var storyboard = UIStoryboard(name: "Main", bundle: nil)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let swiftViewController = storyboard.instantiateViewControllerWithIdentifier("SwiftViewController") as! SwiftViewController
self.swiftViewController = UINavigationController(rootViewController: swiftViewController)

Expand Down
11 changes: 6 additions & 5 deletions SlideMenuControllerSwift/NonMenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ class NonMenuController: UIViewController {
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
coordinator.animateAlongsideTransition(nil, completion: { (context: UIViewControllerTransitionCoordinatorContext!) -> Void in
if let viewController = self.slideMenuController()?.mainViewController as? UINavigationController {
if viewController.topViewController.isKindOfClass(NonMenuController) {
self.slideMenuController()?.removeLeftGestures()
self.slideMenuController()?.removeRightGestures()
}
guard let vc = (self.slideMenuController()?.mainViewController as? UINavigationController)?.topViewController else {
return
}
if vc.isKindOfClass(NonMenuController) {
self.slideMenuController()?.removeLeftGestures()
self.slideMenuController()?.removeRightGestures()
}
})
}
Expand Down

0 comments on commit ad71bcb

Please sign in to comment.