ios - SwiftUI 使用菜单时禁用递归触发器日志记录

标签 ios swift xcode swiftui

大家好我正在使用“菜单”结构来向用户显示可能的选择

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 忽略相关的 subsystemCategory 使用 subsystem: com.apple.UIKitcategory: 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/

相关文章:

swift - 如何将 UInt8 转换为可以连接到字符串的数据类型?

iphone - 一个接一个地运行动画失败

swift - 在用户输入的另一个键中创建一个包含键和值的字典

ios - 纹理缓存不渲染到 iOS 中的帧缓冲区对象

swift 错误 : binary operator '>' cannot be applied to two T operands

ios - 编码的自动布局对于 UITableView 无法正常工作

ios - 设置 Core Plot 饼图图例项目的样式

android - 响应式 Bootstrap 问题

ios - 我正在使用 xcode 9。如何创建内部包含 xib 文件的框架?

javascript - 我该如何处理 "overload"websocket?