与此相关。
当我使用 打开文件QLPreviewController
并按“共享”按钮时,控制台会打印以下日志:
[cloudthumbnails. Generation] 无法确定 file:///Users/xxxxxx/Library/Developer/CoreSimulator/Devices/XXXXXX/data/Containers/Data/Application/XXXXXX/Documents/xxxxxx.pdf 是否为目录:Error Domain= NSCocoaErrorDomain 代码=260
[ShareSheet] 无法请求 fileURL 的默认共享模式:file:///Users/xxxxxx/Library/Developer/CoreSimulator/Devices/XXXXXX/data/Containers/Data/Application/XXXXXX/Documents/xxxxxx.pdf
[ShareSheet] 仅支持 CKShare 和 SWY 类型的加载选项。
[ShareSheet] 获取 URL 项目时出错:file:///Users/xxxxxx/Library/Developer/CoreSimulator/Devices/XXXXXX/data/Containers/Data/Application/XXXXXX/Documents/xxxxxx.pdf
[ShareSheet] 加载 documentURL 的元数据时出错:file:///Users/xxxxxx/Library/Developer/CoreSimulator/Devices/XXXXXX/data/Containers/Data/Application/XXXXXX/Documents/xxxxxx.pdf
但是,路径是正确的(在应用程序的文档文件夹中),并且可以通过任何方式成功打开和共享文件:保存在我的文档、Gmail、AirDrop、Slack 等上。
那么,为什么会出现这些错误呢?我相信我在 Firebase Crashlytics 上收到的以下崩溃可能与此相关:
-[UIDocumentPickerViewController initForExportingURLs:asCopy:] 必须使用指向现有文件的 URL 进行调用:Error Domain=NSCocoaErrorDomain Code=260 UserInfo (NSURL=file:///var/mobile/Containers/Data/Application/APP_ID/Documents/ FILE.pdf,NSFilePath=/var/mobile/Containers/Data/Application/APP/Documents/FILE.pdf,(错误域=NSPOSIXErrorDomain代码=2“没有这样的文件或目录”))
因为我没有[UIDocumentPickerViewController initForExportingURLs:asCopy:]
在应用程序的其他地方调用。调用该方法的唯一方法是从应用程序共享文件并将其存储在 iPhone 文件系统中。
我在 UITableViewCell 中有一个 trailingSwipeAction,其背景颜色必须清晰。
这是我设置操作的代码:
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let myAction = UIContextualAction.init(style: .normal, title: nil) {
// My action code
}
myAction.backgroundColor = .clear
myAction.image = UIImage.init(named: "my-icon")
return UISwipeActionsConfiguration.init(actions: [myAction])
}
Run Code Online (Sandbox Code Playgroud)
但是当没有颜色时,我得到了动作的灰色背景:
我已经下载了苹果提供的 .usdz 模型:https : //developer.apple.com/arkit/gallery/
但是现在,我想用这些模型之一创建一个 SCNNode,所以我这样做是为了获取节点:
guard let urlPath = Bundle.main.url(forResource: "retrotv", withExtension: "usdz") else {
return
}
let mdlAsset = MDLAsset(url: urlPath)
let modelRootNode = SCNScene(mdlAsset: mdlAsset).rootNode
Run Code Online (Sandbox Code Playgroud)
然后我将它添加到场景中,结果是这样的:
为什么它没有纹理?
如您所见,我已将下载的 .usdz 文件放入我的项目目录中的文件夹中:
在小部件内部,有一个按钮,
Button(intent: AnAppIntent()) {
// Button's label.
}
// It seems this modifier does not add any value.
.invalidatableContent()
Run Code Online (Sandbox Code Playgroud)
连接到 AppIntent。
struct AnAppIntent: AppIntent {
static var title: LocalizedStringResource = "An AppIntent"
init() {
// AppIntent required init.
}
func perform() async throws -> some IntentResult {
// Never called when the app is running.
return .result()
}
}
Run Code Online (Sandbox Code Playgroud)
该按钮在点击时会调用 AppIntent ,因此只有在应用程序完全关闭时perform()
才会更新小部件 UI(无论是否带有修饰符.invalidatableContent()
)。
如果应用程序在后台运行,perform()
则不会被调用,并且小部件 UI 永远不会更新。
用户必须明确关闭应用程序才能使小部件按预期工作。
问题可能出在所使用的时间线上。
struct SimpleEntry: TimelineEntry {
let …
Run Code Online (Sandbox Code Playgroud) 我的应用程序及其小部件之间共享一个应用程序组。
我有 SwiftData 的 @Model,从小部件意图的perform()
方法更新并显示在应用程序和小部件上。
@MainActor
func perform() async throws -> some IntentResult {
let context = try ModelContainer(for: MyModel.self).mainContext
let myModel = try ModelContainer(for: MyModel.self).mainContext.fetch(
FetchDescriptor<MyModel>(predicate: #Predicate {
// The predicate is not the problem.
})
).first
myModel?.functionThatModifiesMyModel()
return .result()
}
Run Code Online (Sandbox Code Playgroud)
应用程序和小部件 SwiftUI 都使用宏查看对模型的访问。
@Environment(\.modelContext) var context
@Query(sort: \.whatever) var myModel: [MyModel]
Run Code Online (Sandbox Code Playgroud)
但应用程序代码中的数据永远不正确(使用意图正确更新小部件的数据)。
为什么模型没有出现在应用程序中?
在土耳其语中,有两个i
\n\n问题:每次我大写i时,都会得到一个I。
\n\n当我大写i时,我想得到一个\xc4\xb0(仅在土耳其语中),当我大写\xc4\xb1时,我想得到一个I。
\n\n我有一个函数可以做到这一点
\n\n@objc public static func uppercaseTurkishString(_ string: String) -> String {\n return String(string.map { (char) -> Character in\n if char == "i" {\n return "\xc4\xb0"\n } else {\n return Character(String(char).uppercased())\n }\n })\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n但每次使用时我都必须检查该语言是否是土耳其语,并且为应用程序中的每个字符串执行此操作是一项非常艰巨的工作。
\n\n有更简单的方法吗?
\n我有一个实现协议的枚举:
protocol MyProtocol {
func myFunction()
}
enum MyEnum: MyProtocol {
case caseOne
case caseTwo
case caseThree
}
Run Code Online (Sandbox Code Playgroud)
该协议只有一种方法可以默认实现所有枚举的情况:
extension MyProtocol where Self == MyEnum {
func myFunction() {
// Default implementation.
}
}
Run Code Online (Sandbox Code Playgroud)
但我想为枚举的每种情况创建一个默认实现,如下所示(PSEUDOCODE):
extension MyProtocol where Self == MyEnum & Case == caseOne {
func myFunction() {
// Implementation for caseOne.
}
}
extension MyProtocol where Self == MyEnum & Case == caseTwo {
func myFunction() {
// Implementation for caseTwo.
}
}
extension MyProtocol where …
Run Code Online (Sandbox Code Playgroud)