10 Replies
      Latest reply on May 25, 2020 4:20 AM by eskimo
      quailcreek Level 1 Level 1 (0 points)

        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)")
                    }
                }
            }
        • Re: invalid mode 'kCFRunLoopCommonModes'
          OOPer Level 8 Level 8 (6,145 points)

          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.

          • Re: invalid mode 'kCFRunLoopCommonModes'
            eskimo Apple Staff Apple Staff (13,905 points)

            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"

              • Re: invalid mode 'kCFRunLoopCommonModes'
                Claude31 Level 8 Level 8 (9,165 points)

                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 ?

                • Re: invalid mode 'kCFRunLoopCommonModes'
                  OOPer Level 8 Level 8 (6,145 points)

                  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?

                    • Re: invalid mode 'kCFRunLoopCommonModes'
                      eskimo Apple Staff Apple Staff (13,905 points)

                      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"