Error Handling
Debugging
Programming
Software Development
Code Issues

Warning Attempt to present on which is already presenting null

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

This warning usually appears in iOS when you try to present a view controller while the presenting view controller is already in the middle of presenting another one. In practice, it means your modal presentation logic is firing at the wrong time, from the wrong controller, or more than once.

What the warning actually means

A common example looks like this:

swift
present(alertController, animated: true)

If the current view controller is already presenting something else, UIKit logs a warning like:

text
Attempt to present ... on ... which is already presenting ...

UIKit is telling you that the presentation stack is already busy. It does not know how to present a second modal cleanly from the same controller at that moment.

The most common cause: presenting twice

This often happens when:

  • a button handler fires multiple times
  • the same presentation logic runs in both a callback and a lifecycle method
  • asynchronous code finishes after another modal has already appeared

A simple guard can prevent duplicate presentation:

swift
if presentedViewController == nil {
    present(alertController, animated: true)
}

That is not the entire solution in every case, but it is a good first check.

Present from the correct view controller

Sometimes the real problem is that you are presenting from a controller that is no longer the topmost visible controller. If another controller is already on screen, present from that one instead.

For example, if you are inside a navigation flow, make sure the current visible controller is actually the one doing the presentation.

That matters especially when presentation is triggered from coordinators, global helpers, or async callbacks that outlive the original screen context.

Timing matters in lifecycle methods

Presenting from viewDidLoad is a common source of this warning because the view may not yet be in a stable presentation state. viewDidAppear is usually a safer place when you need to show something immediately after a screen becomes visible.

swift
1override func viewDidAppear(_ animated: Bool) {
2    super.viewDidAppear(animated)
3
4    if presentedViewController == nil {
5        present(alertController, animated: true)
6    }
7}

Even then, make sure the code does not run repeatedly every time the view appears unless that is intentional.

Async callbacks can race with UI state

Network completions, timers, and background-to-main-thread callbacks often trigger modal presentation after the UI has already changed.

swift
1DispatchQueue.main.async {
2    if self.presentedViewController == nil {
3        self.present(alertController, animated: true)
4    }
5}

Dispatching to the main queue is necessary for UIKit, but it is not sufficient by itself. You still need to check whether the controller is in a valid presentation state when the callback finally runs.

Dismiss before presenting something new

If a modal is already on screen and you need to show a different one, dismiss the current modal first or present from the currently visible modal controller.

Trying to stack presentations without coordinating them is one of the easiest ways to produce this warning.

Common Pitfalls

  • Presenting the same alert or modal more than once from repeated callbacks.
  • Presenting from viewDidLoad before the controller is ready for modal UI.
  • Ignoring presentedViewController and assuming the current controller is free to present.
  • Triggering UI presentation from async work without re-checking the current screen state.
  • Presenting from a controller that is no longer the topmost visible controller.

Summary

  • This warning means a view controller is trying to present while it is already presenting something else.
  • The usual fixes are guarding against duplicate presentation and presenting from the correct visible controller.
  • 'viewDidAppear is often safer than viewDidLoad for immediate modal presentation.'
  • Async callbacks must re-check UI state before presenting.
  • Coordinate dismissals and presentations instead of stacking them blindly.

Course illustration
Course illustration

All Rights Reserved.