大家好我正在使用“菜单”结构来向用户显示可能的选择
public struct Menu <Label, Content>: Display where Label: Display, Content: Display
一切似乎都适用于 SwiftUI,但我继续在控制台中收到警告,告诉我:
2021-09-30 20:55:40.032369+0200 [UILog] Called -[UIContextMenuInteraction updateVisibleMenuWithBlock:] while no context menu is visible. This won't do anything.
2021-09-30 20:55:41.344436+0200 [UILog] Called -[UIContextMenuInteraction updateVisibleMenuWithBlock:] while no context menu is visible. This won't do anything.
2021-09-30 20:55:41.414976+0200 [UICollectionViewRecursion] cv == 0x10401dc00 Disabling recursion trigger logging
2021-09-30 20:55:41.417708+0200 [UICollectionViewRecursion] cv == 0x10401dc00 Disabling recursion trigger logging
我哪里做错了?
这是我的菜单代码
private var months: [Date] {
calendar.createDate(
interval: calendar.dateInterval(of: .year, for: Date())
matching: DateComponents(day: 1, hour: 0, minute: 0, second: 0)
)
}
var body: some View {
Menu("Options") {
ForEach(months, id:\.self) { month
Button("\(DateFormatter(format: "MMMM").string(from: month))"){
selectedDate = month }
}
}
}
最佳答案
正如@Minho 所分享的,这似乎是开发人员留下的简单调试/诊断。
对我们来说幸运的是,他们使用了我们都应该使用的 Os.Log
,就像这里所做的一样正确。
使用控制台我们可以识别消息的子系统和类别
console.app logs of related error
然后我们可以告诉 Os.Log
忽略相关的 subsystem
和 Category
使用 subsystem: com.apple.UIKit
和 category: UICollectionViewRecursion
这为我们提供了以下命令,第一个用于系统(设备),第二个用于启动的模拟器。
// Disable forgotten 'UICollectionViewRecursion' debug messages, see.
// https://stackoverflow.com/questions/69397650/swiftui-disabling-recursion-trigger-logging-when-use-menu
// https://twitter.com/caughtinflux/status/1439276097464528896?s=21
sudo log config --mode "level:off" --subsystem com.apple.UIKit --category UICollectionViewRecursion
xcrun simctl spawn booted log config --mode "level:off" --subsystem com.apple.UIKit --category UICollectionViewRecursion
希望这对您有所帮助,请再次在您的项目中使用 Os.Log
。
关于ios - SwiftUI 使用菜单时禁用递归触发器日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69397650/