How does one make an optional closure in swift?

前端 未结 4 2235
悲&欢浪女
悲&欢浪女 2020-11-30 00:32

I\'m trying to declare an argument in Swift that takes an optional closure. The function I have declared looks like this:

class Promise {

 func then(onFulfi         


        
4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 00:54

    Maybe it's a cleaner way. Specially when the closure has complicated parameters.

    typealias SimpleCallBack = () -> ()
    
    class Promise {
    
    func then(onFulfilled: SimpleCallBack, onReject: SimpleCallBack?){       
        if let callableRjector = onReject {
            // do stuff! 
        }
    }
    
    }
    

提交回复
热议问题