How does one make an optional closure in swift?

前端 未结 4 2222
悲&欢浪女
悲&欢浪女 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:56

    You should enclose the optional closure in parentheses. This will properly scope the ? operator.

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

提交回复
热议问题