在使用菜单时禁用递归触发日志记录的 SwiftUI

3

大家好,我正在使用"菜单"结构向用户展示可能的选择。

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 }
                }
            }
      }

         

说是苹果的Bug。 - Minho Yi
1个回答

2

正如@Minho所分享的,这似乎是开发人员留下的简单调试/诊断信息。

幸运的是,他们使用了Os.Log,我们都应该像这里一样正确地使用它。

使用控制台,我们可以识别消息的子系统和类别。

相关错误的console.app日志

然后我们可以告诉Os.Log忽略相关的subsystemCategory,例如subsystem: com.apple.UIKitcategory: UICollectionViewRecursion

这给我们以下命令,第一个用于系统(设备),第二个用于启动的模拟器。

// Disable forgotten 'UICollectionViewRecursion' debug messages, see.
// https://dev59.com/F8Lra4cB1Zd3GeqPGElY
// 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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接