Skip to content

Instantly share code, notes, and snippets.

@baarde
Last active October 11, 2017 15:30
Show Gist options
  • Save baarde/ab56a9ccf47ae97eb9ad to your computer and use it in GitHub Desktop.
Save baarde/ab56a9ccf47ae97eb9ad to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
@protocol OS_Foo <NSObject> @end
typedef NSObject<OS_Foo> * Foo;
@protocol OS_Bar <NSObject> @end
typedef NSObject<OS_Bar> *__attribute__((objc_independent_class)) Bar;
@interface Test : NSObject
@end
@implementation Test
+ (NSArray *)newArray
{
NSArray *array = nil;
return array; // No warning: 'NSArray *' is not overridden
}
+ (NSObject *)newObject
{
NSObject *object = nil;
return object; // Incompatible pointer types returning 'NSObject *' from a function with result type 'Test *'
}
+ (Foo)newFoo
{
Foo foo = nil;
return foo; // Incompatible pointer types returning 'Foo' (aka 'NSObject<OS_Foo> *') from a function with result type 'Test *'
}
+ (Bar)newBar
{
Bar bar = nil;
return bar; // No warning: 'Bar' is not overridden as it is marked as objc_independent_class
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment