105

Environment: Version 11.0 beta 3 (11M362v)

Here's the full text:

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

This message only appears when I click on a UISwitch button that is connected to an action; here, printing "Hello World".

Apparently the behavior of the action isn't affected.

enter image description here

As a comparison, I've created a UIBarButtonItem in the toolbar which behaves normally. So there's something fishy about the switch button.

Question: why would this appear and what does it mean? Remedy?

Frederick C. Lee
  • 9,019
  • 17
  • 64
  • 105
  • Is this using `SwiftUI`? Can you post the code? Using Xcode 11 beta 5 and SwiftUI I also get this error: `invalid mode 'kCFRunLoopCommonModes'` for my `Toggle` views, see SO Question: https://stackoverflow.com/q/57558760/1311272 – Sajjon Aug 19 '19 at 14:52
  • 23
    I have the same issue with a switch on a real device. **Even without any action added** - the error occurs the first time the switch is pressed. Xcode 11.0 iOS 13.1.2 - iPhone Xs – wider-spider Oct 04 '19 at 17:51
  • 4
    Did anyone figure this one out? – Bjørn Ruthberg Oct 16 '19 at 20:05
  • 3
    Any update on this issue? – Ujjwal Nov 06 '19 at 12:19
  • 1
    I am also seeing this message being printed when using a UISwitch in an iOS app written in Objective-C. The UISwitch is on a view that is defined in a storyboard. The UIViewController is being shown by a call to presentViewController: animated: completion: – brant Nov 21 '19 at 21:21
  • 1
    I get the same thing, and the animation is also delayed for some reason – Gigalala Nov 22 '19 at 18:35
  • 1
    For me, the error occurs with a `UISwitch` or a `UIStepper` if I add a target to `UIControlEventValueChanged`, but the error occurs before my target method is actually called, so it isn't related to the code in the target method. It does not occur if I don't add the target. My view controller is running inside a popover, and the popover won't close after it occurs, so it's a real problem and not just a random log message. :-( – arlomedia Dec 06 '19 at 17:35
  • 1
    I see it with a SwiftUI Toggle control (which wraps a UISwitch) on a real device. – Kristopher Johnson Jan 06 '20 at 13:01
  • Another point of data on the Toggle problem: I have my MacBook set to support Tap to Click on the trackpad (System Preferences -> Trackpad -> Tap to click). All other interactions with UI Controls in Simulator work, but tap to click doesn’t register on Toggles. I have to do a regular press (physical click) to get Toggle ui elements to register a click. So, there’s definitely something different about Toggles vs. other UI Controls. [Catalina; Xcode 11] – Grant Neufeld Mar 31 '20 at 12:48
  • Occurs for me Aug 6, 2023 – Doug Null Aug 06 '23 at 14:56

3 Answers3

57

I think it's a warning that Apple should fix it itself. Even in this sample project which is from WWDC19 this problem exists. There is a UISwitch in a cell of a table. When I tap it, the mentioned warning is raised.

So, in my view, it is a bug that Apple should deal with.

Justin
  • 1,786
  • 20
  • 21
30

Judging from the replies by Apple Developer Relations to this post, this is a bug in UIKit and one that Apple is tracking. Until the bug is fixed, the advice is to treat this as "log noise".

pyrmont
  • 225
  • 5
  • 12
Sergey
  • 301
  • 3
  • 4
7

I had a similar problem: When I got the call-back from the UISwitch, I reloaded the UITableView. I think that the call-back is initiated before the UISwitch finishes changing its context, and reloading the cell in that state creates some conflict.

With that theory, I solved my problem like so: I separated the cells into sections, where the cell with the UISwitch was in its own section. When I got the call-back from the UISwitch, I reloaded all the sections except the section that has the cell with the UISwitch.

Shai Balassiano
  • 997
  • 2
  • 10
  • 21
  • 3
    Can you show an example of this in more detail, I have the same issue but don't understand your answer. In my case I don't have a UITableView and some people are using SwiftUI or Interface Builder. Appreciate the help if you can find a universal answer. – Joseph Astrahan Jan 02 '20 at 21:02
  • I use this approach - the switch reloads a different section to the one itself is located in, but I still get the same error. – skaak Feb 01 '20 at 11:12
  • 1
    I also tried separating the UISwitch into its own separate section in a UITableView (static cells), but still have the problem. For me it occurs when calling tableView.beginUpdates() and tableView.endUpdates() in a UIKit app. A google search shows folks are having this problem with Apple's SwiftUI code, and it showed up on some Ray Wenderlich forums. I also see the problem in some of Apple's EveryoneCanCode examples. Perhaps a bug with UISwitch? – Gallaugher Feb 27 '20 at 23:28
  • 1
    It's a known bug Apple is tracking. They claim it is harmless (relatively) and recommend treating it as "log noise." See [this post](https://forums.developer.apple.com/thread/132035) on the Apple dev forums. – Zaphod Feb 25 '22 at 02:46