invalid mode 'kCFRunLoopCommonModes'

invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug


I get this warning when I tap either of the switches shown below. I've tried capturing the switch state in a var and using that to trigger the do/catch statement but no joy. I've even tried pulling the do/catch into separate functions and I still get the warning. Has anybody else run into this and how did you fix it?


@IBAction func greetingFormat_Tapped(_ sender: UISwitch)
    {
        let theQuery = theTable_Settings.filter(settingID == 1)
       
        if sender.isOn
        {
            do {
                if try Database.shared.databaseConnection!.run(theQuery.update(greeting_Format <- "true")) > 0
                {
                    greetingFormatLabel_Outlet.text = NSLocalizedString("HelloMrSmith_String", comment: "")
                } else {
                    print("greeting format true not found")
                }
            } catch {
                print("greeting format true update failed! Error: \(error)")
            }
        } else {
            do {
                if try Database.shared.databaseConnection!.run(theQuery.update(greeting_Format <- "false")) > 0
                {
                    greetingFormatLabel_Outlet.text = NSLocalizedString("HiJoe_String", comment: "")
                } else {
                    print("greeting format false not found")
                }
            } catch {
                print("greeting format false update failed! Error: \(error)")
            }
        }
    }


@IBAction func nonrefundableSwitch_Tapped(_ sender: UISwitch)
    {
        let theQuery = theTable_Settings.filter(settingID == 1)
        var itsOn: String = ""
       
        if sender.isOn
        {
            itsOn = "true"
        } else {
            itsOn = "false"
        }
       
        if itsOn == "true"
        {
            do {
                if try Database.shared.databaseConnection!.run(theQuery.update(nonRefundable_Bool <- "true")) > 0
                {
                    depositDueLabel_Outlet.text = NSLocalizedString("nonRefunddepositisdue_String", comment: "")
                } else {
                    print("nonRefundable true not found")
                }
            } catch {
                print("nonRefundable true update failed! Error: \(error)")
            }
        } else {
            do {
                if try Database.shared.databaseConnection!.run(theQuery.update(nonRefundable_Bool <- "false")) > 0
                {
                    depositDueLabel_Outlet.text = NSLocalizedString("depositisdue_String", comment: "")
                } else {
                    print("nonRefundable false not found")
                }
            } catch {
                print("nonRefundable false update failed! Error: \(error)")
            }
        }
    }

I created a simple sample project with only one UISwitch, its action connected to a method whch did nothing, and got exactly the same message.

2020-04-26 12:56:59.018799+0900 SwitchWarning[43358:4211342] invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution.


Do you have something unexpected after this message?


In my experience, I mark this sort of messages as ignorable (in my mind, not in Xcode menus) as far as my code works as expected.

Thanks for the reply,

Nothing happens except the warning message. I even tried setting the switch action from "value changed" to "touch up inside", got the same warning. Looks to me like a glich with UISwitch.

I had the same message some time ago and finally decided to ignore it.


It was also reported here:

https://stackoverflow.com/questions/56980875/what-does-invalid-mode-kcfrunloopcommonmodes-mean


Could be worth a bug report if not yet done.

The common modes is a meta mode. If you schedule a run loop source in the common modes, the run loop schedules it in all modes that are marked as common (via

CFRunLoopAddCommonMode
). This allows you to schedule a source that runs in the default mode and, say, in the UI framework’s menu tracking mode.

However, when you run the run loop you must always run it in a specific mode. Running the run loop in the common modes is nonsensical, and if you try to do it you get this error.

The correct thing to do here is to set a symbolic breakpoint on

_CFRunLoopError_RunCalledWithInvalidMode
and then look at the backtrace to see who is doing this silliness.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

So that's not a bug but a real programming error ?


Were typically, for a switch, would one set the correct mode ? And what is this correct mode ?

The correct thing to do here is to set a symbolic breakpoint on

_CFRunLoopError_RunCalledWithInvalidMode
and then look at the backtrace to see who is doing this silliness.

Of course I did it.

Thread 1 Queue : com.apple.main-thread (serial)

#0 0x00007fff23d9b6e0 in _CFRunLoopError_RunCalledWithInvalidMode ()

#1 0x000000010d390e8e in _dispatch_client_callout ()

#2 0x000000010d3923db in _dispatch_once_callout ()

#3 0x00007fff23d9b8f9 in CFRunLoopRunSpecific ()

#4 0x00007fff48601250 in __88-[UISwitchModernVisualElement _handleLongPressWithGestureLocationInBounds:gestureState:]_block_invoke ()

#5 0x00007fff48c2242e in _runAfterCACommitDeferredBlocks ()

#6 0x00007fff48c12bbc in _cleanUpAfterCAFlushAndRunDeferredBlocks ()

#7 0x00007fff48c43315 in _afterCACommitHandler ()

#8 0x00007fff23da1067 in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()

#9 0x00007fff23d9bb1e in __CFRunLoopDoObservers ()

#10 0x00007fff23d9c06a in __CFRunLoopRun ()

#11 0x00007fff23d9b884 in CFRunLoopRunSpecific ()

#12 0x00007fff38b5ac1a in GSEventRunModal ()

#13 0x00007fff48c19220 in UIApplicationMain ()

#14 0x000000010d11dacb in main at /Users/dev/Projects/experimental/SwitchWarning/SwitchWarning/AppDelegate.swift:12

#15 0x00007fff519b910d in start ()

#16 0x00007fff519b910d in start ()


Who do you think is doing?

Wow, that was depressingly easy to reproduce. I did a little digging and this is definitely a bug in UIKit, one that we’re tracking as (r. 57322394). The good news is that, AFAICT, it’s not actively toxic. CF is coping with this misbehaviour in a reasonable way.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks!

Hi Folks, I am getting the same issue and looks like UISwitch is broke. Is the fix for this comming soon ?

The issue happens when you toggle the switch even when it is not connected to any IBAction...

Is the fix for this comming soon ?

I can’t talk about The Future™ [1].

Other than the log message, is this causing your any problems? If not, my advice is that you treat this as log noise.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

[1] My standard YouTube link for this has been taking down. I am most sad )-;

FWIW, this error is also occurring using a Toggle in SwiftUI. The toggle won't move!
NB. RESOLVED below is now working

Have this same message in SwiftUI and the attached method isn't called. Is it something I'm doing wrong?
Code Block
Toggle(isOn: self.$isOn) {
            EmptyView()
  }
.onChange(of: self.isOn) { _ in
            print("**DEBUG - \(self.isOn)")
   }

System:
Xcode 12.1 GM seed
6th Gen iPad mini - iPadOS 14.1

I am trying to write tests that involve a switch and am getting the popup "Timestamped Event Matching Error: Failed to find matching element".

Any ideas on how to proceed?

It's January 2, 2022 and this still occurs.

Still happening.

@eskimo writes: Other than the log message, is this causing ... any problems?

YES!

For a sheet with an @ObservedObject object with date and isToggle members having the UI with a DatePicker and Toggle, changing the date to today's date--whatever today happens to be when running--then toggling cause the sheet to go away--poof--back to the previous view WHEN IN DEBUG MODE. This does not happen in release.

January 18, 2022

January 21, 2022... and here I am! Yes, still happening.

I am also seeing problems when getting this error. The NavigationLink view that this toggle is on is dismissed when toggling and goes back to the previous view. It is quite annoying. As @swiftaero mentioned above the issue is happening in the sim and on device while developing the app, I have not released the app yet so I can't test it on deployment or in TestFlight.

2 Interesting things about my situation with this error is that it is happening when I toggle an @AppStorage binding. If I change it to an @State binding it does not dismiss the view back to the previous one. Also the view has a list of core data records from an @FetchRequest and this error happens and dismisses the view when I delete a record from the list with .onDelete.

I have tried to replicate this issue in another app and I get the error but not the dismissing of the view. My current line of thinking is that the error&dismiss is linked to editing an object that lives outside of the view. But I am defiantly stumped at this point and will have to see if it happens in TestFlight like @swiftaero mentioned.

Still happening for SwiftUI Toggle March 24 2022

5 April, 2022 and this still happening.Not an April foil! believe me!!— iSimoo less than a minute ago 

14 July, 2022 Still happening

"invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution."

still habbening

iOS 16.0 RTM, still happening with a plain SwiftUI Toggle.

Oct 12, 2022, and still receive the same error for UISwitch with and without actions attached. `2022-10-12 14:29:00.726306-0400 [REDACTED][4322:62624] invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution.

still happening

2022-10-14 19:28:59.391056+0200 Solingen[2557:1069151] invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution.
invalid mode 'kCFRunLoopCommonModes'
 
 
Q