UIAlertView
iOS 9
deprecation
iOS development
UIAlertController

UIAlertView first deprecated IOS 9

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

UIAlertView is deprecated and replaced by UIAlertController. Modern iOS code should always use UIAlertController for alerts and action sheets, because it integrates with view-controller presentation flow and closure-based actions.

Core Sections

1) Legacy vs modern API

Legacy Objective-C pattern:

objective-c
1UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title"
2                                                message:@"Message"
3                                               delegate:self
4                                      cancelButtonTitle:@"OK"
5                                      otherButtonTitles:nil];
6[alert show];

Modern Swift pattern:

swift
let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default))
present(alert, animated: true)

2) Action sheet specifics

swift
let sheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
sheet.addAction(UIAlertAction(title: "Delete", style: .destructive))

On iPad, set popover anchor before presenting.

3) Migrate delegate logic to closures

swift
alert.addAction(UIAlertAction(title: "Confirm", style: .default) { _ in
    self.performDelete()
})

This replaces old delegate callback branching.

4) Presentation context checks

Present from the visible view controller on the main thread.

swift
DispatchQueue.main.async {
    self.present(alert, animated: true)
}

Validation and Deployment Readiness

After applying the solution in this topic, use a repeatable verification sequence so fixes remain stable across environments and future refactors. The most reliable pattern is: reproduce baseline behavior, apply one focused change, then re-run the same checks and compare outputs. This avoids false confidence from incidental improvements.

A compact verification loop:

bash
1# 1) baseline capture
2./run_case.sh > before.txt
3
4# 2) apply targeted fix from this guide
5# keep the diff focused and minimal
6
7# 3) verify and compare
8./run_case.sh > after.txt
9diff -u before.txt after.txt

If your repository includes automated tests, convert the reproduced issue into a regression test immediately. This transforms one-time troubleshooting into long-term protection and catches behavior drift early during upgrades.

bash
1# example quality gates
2./lint.sh
3./test.sh
4./smoke.sh

Run at least one edge-case pass in addition to nominal-path checks. Real-world failures often appear on boundary inputs: empty payloads, null values, large datasets, malformed encodings, unusual locale/timezone settings, or high-concurrency requests. Document expected behavior for those edge cases so reviewers and on-call engineers can reproduce outcomes quickly.

Validate environment parity before rollout. A fix that succeeds locally can fail in staging/production due to version mismatches, architecture differences, network policies, or filesystem semantics. Capture runtime/tool metadata alongside test evidence.

bash
1python --version
2node --version
3java -version
4git rev-parse --short HEAD

Define rollback criteria before deployment. Identify which metrics/logs indicate success or regression, and document the rollback command path. This operational discipline reduces incident duration and prevents repeated firefighting for the same class of issue.

Finally, isolate behavior changes from unrelated formatting or dependency churn. Smaller, focused commits are easier to review, bisect, and revert safely. If normalization or tooling updates are required, ship them separately to keep risk controlled.

Common Pitfalls

  • Keeping UIAlertView helper wrappers in modern targets.
  • Forgetting iPad popover source for action sheets.
  • Presenting from detached or already-dismissed controllers.
  • Migrating syntax but leaving old delegate architecture unchanged.
  • Triggering alert presentation from background queue.

Summary

Use UIAlertController exclusively on modern iOS. Migration should include both API replacement and control-flow updates. Proper presentation context and iPad handling make alert behavior stable across devices.

A practical long-term safeguard is to keep one regression test for the core behavior and one edge-case test for boundary inputs (empty values, malformed payloads, or large datasets). Run both in CI on every dependency/runtime upgrade. This catches compatibility drift early and prevents repeated production incidents that otherwise look unrelated. When possible, attach a short runbook entry with exact verification commands so teammates can reproduce outcomes quickly during troubleshooting.

Include this check in your release checklist and rerun it after any library/runtime upgrade. A small, repeatable smoke test here usually prevents subtle regressions that are expensive to diagnose later in production.


Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.