gpt4 book ai didi

Xcode代码补全提示 `printContent(_)`以上 `print(_)`

转载 作者:行者123 更新时间:2023-12-05 05:54:44 25 4
gpt4 key购买 nike

使用 Xcode 13,键入 print 的任何子字符串建议 printContent() 在 Xcode 代码完成列表中位于常见的 Swift print() 之上> 函数。

printContent first in list

printContent(_ sender: Any?)
Tells your app to print available content.

“跳转到定义”显示以下声明,2021 年 iOS 15 的新声明:

public protocol UIResponderStandardEditActions : NSObjectProtocol {

// ...

@available(iOS 15.0, *)
optional func printContent(_ sender: Any?)
}

什么是 printContent() 函数以及如何使用它?

它是否以任何方式更好地替代 print(),证明其在 Xcode 中突出的代码完成位置是合理的?

如果不是,我怎样才能回到 Xcode 13 之前的行为并在列表中首先建议极其常见的 print() 函数?

最佳答案

如果您的应用在其 Info.plist 文件中包含 UIApplicationSupportsPrintCommand 键,人们可以使用键盘快捷键 Command-P 从您的应用打印,它调用 打印内容(_:)。您还可以将 printContent(_:) 设置为对其他打印相关控件(例如工具栏上的打印按钮)的操作。

override func printContent(_ sender: Any?) {
let info = UIPrintInfo.printInfo()
info.outputType = .photo
info.orientation = .portrait
info.jobName = modelItem.title

let printInteractionController = UIPrintInteractionController()
printInteractionController.printInfo = info
printInteractionController.printingItem = modelItem.image

let completionHandler: UIPrintInteractionController.CompletionHandler = {
(controller: UIPrintInteractionController, completed: Bool, error: Error?) in
if let error = error {
Logger().error("Print failed due to an error: \(error.localizedDescription)")
}
}

if traitCollection.userInterfaceIdiom == .pad {
if let printButton = navigationItem.rightBarButtonItem {
printInteractionController.present(from: printButton, animated: true, completionHandler: completionHandler)
}
} else {
printInteractionController.present(animated: true, completionHandler: completionHandler)
}
}

Apple developer link

关于Xcode代码补全提示 `printContent(_)`以上 `print(_)`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69588633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com