2016-08-09 135 views
1

我試圖運行關閉,但我收到一個錯誤。無法將類型'()'的值轉換爲結束結果類型'Bool'。我不確定我在這裏做錯了什麼。快速關閉不起作用

func runPrintCycle(){ 
     self.runPrinter1() { success in 
      self.runPrinter2() { success in 
       print("Success") 
      } 
     } 
    } 

    func runPrinter1(completionHandler: (Bool) -> Bool){ 
     if let printer1 = Workstation.instance.printer1{ 
      let receiptPrinter = Print(printer: printer1) 
      receiptPrinter.runPrinterReceiptSequence() { success in 
       completionHandler(true) 
      } 
     }else{ 
      completionHandler(true) 
     } 
    } 

func runPrinter2(completionHandler: (Bool) -> Bool){ 
      if let printer2 = Workstation.instance.printer2{ 
       let receiptPrinter = Print(printer: printer2) 
       receiptPrinter.runPrinterReceiptSequence() { success in 
        completionHandler(true) 
       } 
      }else{ 
       completionHandler(true) 
      } 
     } 

回答

2

你可能不需要聲明completeon關閉在runPrinter函數返回值Bool。讓他們改爲返回Void。當打印機未找到時,您可能還想發送false關閉:

func runPrintCycle() { 
    self.runPrinter1() { success in 
     print("Printer 1: \(success)") 
     // put here if(success) if you wish run second printer only on success 
     self.runPrinter2() { success in 
      print("Printer 2: \(success)") 
     } 
    } 
} 

func runPrinter1(completionHandler: (Bool) ->()) { 
    if let printer1 = Workstation.instance.printer1 { 
     let receiptPrinter = Print(printer: printer1) 
     receiptPrinter.runPrinterReceiptSequence() { success in 
      completionHandler(true) //probably success instead true? 
     } 
    }else{ 
     completionHandler(false) 
    } 
} 

func runPrinter2(completionHandler: (Bool) ->()){ 
    if let printer2 = Workstation.instance.printer2{ 
     let receiptPrinter = Print(printer: printer2) 
     receiptPrinter.runPrinterReceiptSequence() { success in 
      completionHandler(true) //probably success instead true? 
     } 
    }else{ 
     completionHandler(false) 
    } 
}