Last active
March 13, 2018 22:06
-
-
Save bdash/54014e09a79a6145ed26978b5bc23b96 to your computer and use it in GitHub Desktop.
Using Objective-C generics with type constraints on forward-declared classes?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface Base : NSObject | |
@end | |
@interface GenericCollection<T: Base *> : NSObject | |
@end | |
@class Derived2; | |
@interface Derived1 : Base | |
@property (strong) GenericCollection<Derived2 *> *collection; | |
@end | |
@interface Derived2 : Base | |
@property (strong) GenericCollection<Derived1 *> *collection; | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Deferring the property declaration to a class extension works:
In a real-world setting it would likely require introducing an additional header file that both Derived1.h and Derived2.h import.