How To Simulate Memory Warning In Xcode 10 iOS Simulator

When you develop iOS app, you sometimes need to simulate memory warning notification to test your iOS app in high memory pressure condition. Xcode simulator just provide such a tool for you to trigger memory warning notification. Then you can test your source code in ViewController class’s didReceiveMemoryWarning function. This article will tell you how to do it.

1. Simulate Memory Warning Notification In Xcode iOS Simulator Steps.

  1. First create a Xcode project.
  2. Then override and write some code in your ViewController class’s didReceiveMemoryWarning function like below. The class file name is ViewController.swift.
    override func didReceiveMemoryWarning() {
        print("view receive memory warning.")
    }
  3. Now start an iOS simulator to run your Xcode iOS app project.
  4. When the iOS simulator start up, click it to focus on it, then click Debug —> Simulate Memory Warning menu item at the simulator top menu bar. This menu item will send the memory warning notification in the iOS simulator, and your app will receive the memory warning notification, and then run the code in ViewController class’s didReceiveMemoryWarning function.
    click menu item simulator ---> debug ---> simulate memory warning
  5. Now you can see the output text in Xcode debug console as below.
    view receive memory warning.
  6. If you do not know how to display the Xcode debug console and see the output text, please read article How To Debug And Get Error Messages In Xcode Step By Step
READ :   How To Download iOS Simulator To Fix Xcode Error Can't Select iOS Simulator

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.