Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI Disabling recursion trigger logging when use Menu

Hi everyone I'm using the "Menu" structure to display the possible choices to the user

public struct Menu <Label, Content>: Display where Label: Display, Content: Display 

Everything seems to work with SwiftUI but I continue to receive alerts in the console that tell me this:

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

Where am I doing wrong ?

This is my code for the Menu

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

         
like image 785
kAiN Avatar asked Jan 22 '26 08:01

kAiN


1 Answers

As @Minho shared it's seems to be a simple debug / diagnostic left by a dev.

Fortunately for us they used Os.Log which we should all use, correctly like it is done here.

Using the console we can identify the subsystem and category of the messages

console.app logs of related error

We can then tell Os.Log to ignore the related subsystem and Category With subsystem: com.apple.UIKit and category: UICollectionViewRecursion

This give us the following commands, the first for system (device), the second for the booted simulator.

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

Hope this helps and again please use Os.Log in your projects.

like image 119
Lifely Avatar answered Jan 25 '26 06:01

Lifely



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!