[英]Swift: Result of call to function within viewWillTransition is unused
[英]Result of call to function returning Bool is unused
今天早上剛剛更新到 XCode 14 並收到這個奇怪的警告
調用 function 返回“Bool”的結果未使用
使用當前 function 通過 AirPrint 進行打印時。 這在 XCode 13 中不是問題,我看不出它現在發生的任何原因,除非 Swift 6 中發生了某些變化。
希望有人知道答案。
這是 function:
/// Prints the PDF file using airprint
func printPDF() {
let pdfFileURL = FileManager.default.temporaryDirectory.appendingPathComponent(
"Filename.pdf"
)
let printController = UIPrintInteractionController.shared
let printInfo = UIPrintInfo(dictionary: nil)
printInfo.jobName = "Print PDF"
printInfo.outputType = .general
printController.printInfo = printInfo
printController.printingItem = pdfFileURL
printController.present(animated: true) { (_, isPrinted, error) in // <-- Result of call to function returning 'Bool' is unused
if error == nil {
if isPrinted {
print("Print Success")
} else {
print("Print Failed: \(error?.localizedDescription ?? "No Error")")
}
}
}
} // End Func
根據文檔,function 的簽名是:
func present(animated: Bool, completionHandler: UIPrintInteractionController.CompletionHandler?) -> Bool
如果您不需要返回值,請使用:
let _ = printController.present(animated: true) { (_, isPrinted, error) in
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.