Skip to content

Instantly share code, notes, and snippets.

@steipete
Last active June 6, 2017 03:56
Show Gist options
  • Star 51 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save steipete/5626678 to your computer and use it in GitHub Desktop.
Save steipete/5626678 to your computer and use it in GitHub Desktop.
This method will help to prevent a lot of emails about "weird bugs".
// Defines a yet undocumented method to add a warning if super isn't called.
#ifndef NS_REQUIRES_SUPER
#if __has_attribute(objc_requires_super)
#define NS_REQUIRES_SUPER __attribute((objc_requires_super))
#else
#define NS_REQUIRES_SUPER
#endif
#endif
@interface UIViewController (SubclassingWarnings)
// PSPDFKit overrides all kind of event hooks for UIViewController.
// You should always call super on those, even if you're just using UIViewController.
- (void)viewWillAppear:(BOOL)animated NS_REQUIRES_SUPER;
- (void)viewDidAppear:(BOOL)animated NS_REQUIRES_SUPER;
- (void)viewWillDisappear:(BOOL)animated NS_REQUIRES_SUPER;
- (void)viewDidDisappear:(BOOL)animated NS_REQUIRES_SUPER;
- (void)viewWillLayoutSubviews NS_REQUIRES_SUPER;
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration NS_REQUIRES_SUPER;
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration NS_REQUIRES_SUPER;
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation NS_REQUIRES_SUPER;
- (void)didReceiveMemoryWarning NS_REQUIRES_SUPER;
@end
@mbinna
Copy link

mbinna commented Nov 27, 2013

This does not work for me (Xcode 5.0.2, Build 5A3005). However, it works if I redeclare the UIViewController methods with NS_REQUIRES_SUPER in a category on PSPDFViewController (instead of in a category on UIViewController).

@steipete Any comments, hints, or ideas about that behavior and why it does not work with the Gist above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment