美文网首页
swift5.0 尾随闭包

swift5.0 尾随闭包

作者: marlonxlj | 来源:发表于2021-09-22 16:45 被阅读0次
    func play1(param1:String,param2:(String) ->Void)
    {
        param2(param1 + "---swift")
    }
    
    //play1(param1: "hello", param2: {(data:String) -> Void in
    //    print(data)
    //})
    
    play1(param1: "world") { (data) in
        print(data)
    }
    
    func play2(param:(String) -> String)
    {
        var value = param("swift")
        
        print("返回值:\(value)")
        
    }
    
    //play2(param: {(data) -> String in
    //
    //    return data + "--ios"
    //})
    play2 { (data) -> String in
        return data+"---ios1"
    }
    
    func play3(parm:() -> Void)
    {
        parm()
    }
    
    play3(parm:{
        print("play3")
    })
    
    play3(){
        print("play3")
    }
    
    play3 {
        print("play3")
    }
    
    func play4(param:() -> String)
    {
        var value = param()
        print("value =\(value)")
    }
    
    play4(param: {()->String in
        return " hello"
    })
    
    play4(){() -> String in
        return "hello world"
    }
    
    play4 { () -> String in
        return " play4 ---"
    }
    
    play4{
        return " dsds"
    }
    
    func play5(param1:(Int) -> Void, param2:Int)
    {
        param1(param2 * 2)
    }
    
    play5(param1: {(data:Int) -> Void in
        print(data)
    }, param2: 100)
    
    play5(param1: {(data) in
        print(data)
    }, param2: 100)
    
    

    相关文章

      网友评论

          本文标题:swift5.0 尾随闭包

          本文链接:https://www.haomeiwen.com/subject/wnybpltx.html