UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Project 12 | Day 49 | UserDefaults & Challenge 2: UIAlertController on UINavigationController which is already presenting

Forums > 100 Days of Swift

Hello everyone! I hope you're all safe and well.

Just to make sure I understood reading and writing on UserDefaults, we can safely use defaults.set(highestScore, forKey: "HighScore") to write and highestScore = defaults.integer(forKey: "HighScore") to read when we know for sure the type of data we're working with (like in the Challenges) and use NSCoding or Codable only for our own classes, right?

I am trying to solve Challenge 2 of Project 12 by saving the player’s highest score, and showing a special message if their new score beat the previous high score, but I am getting this error:

[Presentation] Attempt to present <UIAlertController: 0x7fa6c4875c00> on <UINavigationController: 0x7fa6c581d800> (from <project2.ViewController: 0x7fa6c45099d0>) which is already presenting <UIAlertController: 0x7fa6c583a800>.

I check several conditions in the @IBAction func buttomTapped(_ sender: UIButton) method that present several UIAlertController depending on the result. From what I've read on Stack Over Flow, we're supposed to dismiss the current UIAlertController before presenting a new one using closures, but I am unable to understand how it's done. Has anyone experienced this?

Thanks in advance for your time and response. KB

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.