• SWIFT 闭包的简单使用二


    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 { () -> Int in
                print("回调")
                return 20
            }
        }
        /**
         * 闭包返回整型数据
         */
        func processData(printSomething:()->Int){
            print("执行操作")
            //执行闭包回调
            let num = printSomething()
            print("闭包返回值num:(num)")
        }
    
    }
  • 相关阅读:
    奔跑的绵羊js
    13.差分
    12.子矩阵的和
    11.前缀和
    10.高精度除法
    9.高精度乘法
    8.高精度减法
    7.高精度加法
    6.数的三次方根
    5.数的范围
  • 原文地址:https://www.cnblogs.com/lantu1989/p/5205387.html
Copyright © 2020-2023  润新知