A base view controller class that when running on the simulator in debug mode, will auto simulate a memory warning every time the view controller's viewDidAppear is called
// | |
// BaseViewController.m | |
// | |
// Created by Peter Boctor on 5/4/11. | |
// | |
// Copyright (c) 2011 Peter Boctor | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is | |
// furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in | |
// all copies or substantial portions of the Software. | |
// | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
// THE SOFTWARE | |
#import "BaseViewController.h" | |
@interface BaseViewController (Private) | |
- (void)simulateMemoryWarning; | |
@end | |
@implementation BaseViewController | |
- (void) viewDidAppear:(BOOL)animated | |
{ | |
[super viewDidAppear:animated]; | |
#if TARGET_IPHONE_SIMULATOR | |
#ifdef DEBUG | |
// If we are running in the simulator and it's the DEBUG target | |
// then simulate a memory warning. Note that the DEBUG flag isn't | |
// defined by default. To define it add this Preprocessor Macro for | |
// the Debug target: DEBUG=1 | |
[self simulateMemoryWarning]; | |
#endif | |
#endif | |
} | |
- (void)simulateMemoryWarning | |
{ | |
#if TARGET_IPHONE_SIMULATOR | |
#ifdef DEBUG | |
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"UISimulatedMemoryWarningNotification", NULL, NULL, true); | |
#endif | |
#endif | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment