Skip to content

Instantly share code, notes, and snippets.

@DarthMike
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarthMike/1add91a7f5b5bf18c326 to your computer and use it in GitHub Desktop.
Save DarthMike/1add91a7f5b5bf18c326 to your computer and use it in GitHub Desktop.
Nullability and weak. Inconsistency in warnings but works
NS_ASSUME_NONNULL_BEGIN
@interface ViewController : UIViewController
// Note it's a weak property and compiler does not complain.
// Anyway the property will be nullified by the runtime as it has always been. Annotations don't affect generated code.
@property (nonatomic, weak) id delegate;
@end
NS_ASSUME_NONNULL_END
// Using it:
id delegate = [[NSObject alloc] init];
ViewController *controller = [[ViewController alloc] initWithNibName:nil bundle:nil];
controller.delegate = delegate;
delegate = nil; // controller.delegate is nil as expected. Generated code does not change.
controller.delegate = nil; // Generates warning at compile time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment