[Swift] function pointer(address) as the parameter of function

前端之家收集整理的这篇文章主要介绍了[Swift] function pointer(address) as the parameter of function前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1 return func pointer(address)

func getFuncPointer()->(Int->Int){
    func add(num:Int)->Int{
        return num+1;
    }
    return add;
}
var f = getFuncPointer();
println(f(100))

2 function pointer(address) as the parameter of function

func lessThanTen(num:Int)->Bool{
    return num < 10;
}

func hasAnyMatch(list:[Int],condition:Int->Bool)->Bool{
    for item in list{
        if condition(item){
            return true
        }
    }
    return false
}
var B:Bool = hasAnyMatch(arr,lessThanTen);
println(B)
原文链接:https://www.f2er.com/swift/326448.html

猜你在找的Swift相关文章