How to handle Void success case with Result lib (success/failure)

前端 未结 3 2042
Happy的楠姐
Happy的楠姐 2021-01-11 14:49

Introduction:

I\'m introducing a Result framework (antitypical) in some points of my app. In example, given this function:

func find         


        
3条回答
  •  自闭症患者
    2021-01-11 15:11

    Try this

    Note this is example you can change as per your test

    typealias resultHandler = (_ responseItems: AnyObject, _ error: Error) -> Void
    
    func deleteItem(byId: Int, completion: resultHandler){
           completion(Items, error) 
     }
    

    Calling

    self.deleteItem(byId: 1) { (result, error) in
                if error ==nil{
    
                }
            }
    

提交回复
热议问题