UISlider valueChanged has uninitialized UIEvent

This issue was in the first iOS 26 beta and it still there with Xcode 26 beta 6 (17A5305f). Feedback is FB18581605 and contains sample project to reproduce the issue.

I assign a target and action to a UISlider for the UIControl.Event.valueChanged value:

addTarget(self, action: #selector(sliderValueDidChange), for: .valueChanged)

Here’s the function.

@objc
func sliderValueDidChange(_ sender: UISlider, event: UIEvent) {
    print(event)
}

When printing the event value, there is a crash. When checking the event value with lldb, it appears uninitialized.

Thanks for filling the bug report.

Update your function signature to

 slider.addTarget(self, action: #selector(sliderValueDidChange(_:for:)), for: .valueChanged)

and the method to

  @objc
    private func sliderValueDidChange(_ sender: UISlider, for event: UIEvent) {
        print("Slider value changed to: \(sender.value)")
        print("Event: \(event)")
    }

See Responding to control-based events using target-action for examples on defining action methods you use to respond to events

Thanks for taking the time to answer. It's still crashing with your recommendation (screenshot 2) and lldb still shows an uninitialized pointer (screenshot 1).

Also, I should add that this starts crashing with iOS 26 betas. It has been working fine with every iOS version so far.

.

Effectively, your code crashes in Xcode 26 / iOS 26 (but works in Xcode 16.4 / iOS 18.4).

I think problem is the type used for event.

I changed UIEvent in sliderValueDidChange:

@objc func sliderValueDidChange(_ sender: UISlider, for event: UIEvent) {

to UIControl.Event

@objc func sliderValueDidChange(_ sender: UISlider, for event: UIControl.Event) {
    print("Slider value changed to: \(sender.value) ")
    print(event)
}

No more crash, just the log:

Slider value changed to: 0.025641026 
UIControlEvents(rawValue: 0)
Slider value changed to: 0.03926282 
UIControlEvents(rawValue: 0)

Did Xcode 26 replaced UIEvent by UIControl.Event ? In that case I could not find it in documentation.

That's at least a documentation bug (or an error compiler should detect).

I note the modified code also works with Xcode 16.4 / iOS 18.4, but givesa different UIControlEvents value

Slider value changed to: 0.00042842288 
UIControlEvents(rawValue: 105553178306624)
Slider value changed to: 0.0038560412 
UIControlEvents(rawValue: 105553178306624)

So, yes, I think it is worth a bug report, because many of us will face the issue.

Let's wait for DTS engineer analysis, in case. Then close the thread.

[@Bigby Woody](https://developer.apple.com/forums/profile/Bigby Woody) Could you please test the code snippet I’ve provided in Xcode beta 6 and iOS 26 beta 7? I’d like to know if you’re still able to reproduce the runtime exception.

@DTS Engineer unfortunately yes. I reproduced with Xcode 26 beta 6 (17A5305f) and an iPad running iOS 26 beta 7 (23A5326a).

The following code will produce the runtime exception.

 slider.addTarget(
  self, 
  action: #selector(sliderValueDidChange(_:for:)), 
  for: .valueChanged
)
// ...
@objc
func sliderValueDidChange(_ sender: UISlider, for event: UIEvent) {
  print(event)
}

whereas changing the event parameter type to UIControl.Event doesn't produce it:

@objc
func sliderValueDidChange(_ sender: UISlider, for event: UIControl.Event) {
  print(event)
}

Do note that changing the action method body to


@objc
func sliderValueDidChange(_ sender: UISlider, for event: UIEvent) {
  print("Event: \(event)")
}

has always been working fine, but that is because the String interpolation treats the event value as nil I believe (by printing an empty String).

So the question is: did the required signature for selector change in Xcode 26 ? I have noticed the same issue for other types of control.

I have the same issue in my project. We have always used UIEvent and it had always worked. Now we always get nil. What are the official guidelines now? How are we supposed to use this API? It seems like a bug in the framework and the responsible Apple team should fix it.

Found another issue also. Add a UISlider inside a UIScrollView. Then just touch and release the slider thumb. The events that are received are:

  1. touchUpInside/touchUpOutside
  2. valueChanged
  3. touchDown

What is happening is that we receive that we have a touch down after we received the touch up -> you cannot init some code in the touch down because no touch up will come and the state of the code is broken. I reported the issue to Apple at FB20388909

Same issue here. There is not much to be done until Apple fixed their framework, but I'd like to share my workaround.

Unfortunately, using UIControl.Event instead of UIEvent does not work as advertised. The call just typecasts the pointer (UIEvent*)nil to the value UIControl.Event; that explains why the event always results in UIControlEvents(rawValue:0).

My event handler used to look like this:

    @IBAction internal func sliderValueChanged(_ sender: Any, forEvent event: UIEvent) 
{
  if let touchEvent = event.allTouches?.first {
    switch touchEvent.phase {
      case .began: ...
      case .moved: ...
      case .ended: ...
      default: break
     }
  }
}

Since the event is not much of any help anymore, I've replaced the old handler with three distinct ones:

@IBAction internal func sliderValueChanged(_ sender: Any, forEvent event: UIEvent) { ... }

@IBAction func sliderDidBeginValueChange(_ sender: Any) { ... }

@IBAction func sliderDidEndValueChange(_ sender: Any) { ... }

The handler sliderDidBeginValueChange is connected to "Touch Down" and the handler sliderDidEndValueChange is connected to "Touch Cancel", "Touch Up Inside" and "Touch Up Outside".

This allows to mimic the old behaviour for now.

UISlider valueChanged has uninitialized UIEvent
 
 
Q