Last active
August 29, 2015 14:06
-
-
Save susemeee/d138908e983de80f5dcd to your computer and use it in GitHub Desktop.
Segmentation fault bug in Swift language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// SwiftBug | |
// | |
// Created by *守細美 on 9/25/14. | |
// Copyright (c) 2014 iplab. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
let handler = completedHandler(self, "register") | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
typealias DLDefaultCompletionHandler = (success: Bool, message: String?) -> () | |
//swift compiler has a bug while returning closures in a closure | |
let completedHandler: (AnyObject, String) -> (DLDefaultCompletionHandler) = { (me, title) in | |
return | |
{(success, message) -> () in | |
if success{ | |
//proceed to main controller | |
let tabView : UITabBarController = UITabBarController(nibName: nil, bundle: nil) | |
let naviController: UINavigationController = UINavigationController(rootViewController:tabView) | |
me.presentViewController(naviController, animated: true, completion: nil) | |
}else{ | |
println("\(title) failed") | |
} | |
} | |
} | |
} | |
Solution
//
// ViewController.swift
// SwiftCrashTest
//
// Created by Luavis on 9/26/14.
// Copyright (c) 2014 Luavis. All rights reserved.
//
import UIKit
typealias DLDefaultCompletionHandler = (success: Bool, message: String?) -> ()
class ViewController: UIViewController {
let completedHandler: (AnyObject, String) -> (DLDefaultCompletionHandler);
required init(coder aDecoder: NSCoder)
{
self.completedHandler = { (me, title) in
return
{(success, message) -> () in
if success{
//proceed to main controller
let tabView : UITabBarController = UITabBarController(nibName: nil, bundle: nil)
let naviController: UINavigationController = UINavigationController(rootViewController:tabView)
me.presentViewController(naviController, animated: true, completion: nil)
}else{
println("\(title) failed")
}
}
}
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
let handler = completedHandler(self, "register")
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
크;