码迷,mamicode.com
首页 > 编程语言 > 详细

SWIFT 闭包的简单使用

时间:2016-02-21 19:54:17      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        // Override point for customization after application launch.
        self.window!.backgroundColor = UIColor.whiteColor()
        
        self.window!.rootViewController = RootViewController()
        
        self.window!.makeKeyAndVisible()
        return true
    }
}
import UIKit

class RootViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //调用processData函数
        processData { () -> () in
            print("被回调了");
        }
    }
    
    func processData(printSomething:()->()){
        print("执行操作");
        //执行闭包回调
        printSomething();
    }

}

 

SWIFT 闭包的简单使用

标签:

原文地址:http://www.cnblogs.com/lantu1989/p/5205367.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!