Last active
November 8, 2016 21:27
-
-
Save sodastsai/b4c2147b7b1aef467b5a548570a0036d to your computer and use it in GitHub Desktop.
ObjC Generic
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
@interface BaseViewModel : NSObject | |
- (void)baseMethod; | |
@end | |
@implementation BaseViewModel | |
- (void)baseMethod {} | |
@end | |
// --------------------------------------------------------------------------------------------------------------------- | |
@interface BaseViewController<__covariant ViewModelType: BaseViewModel *> : UIViewController | |
@property (nonatomic, strong) ViewModelType viewModel; | |
@end | |
@implementation BaseViewController | |
- (void)ha { | |
[self.viewModel baseMethod]; | |
} | |
@end | |
// ===================================================================================================================== | |
@interface MyViewModel : BaseViewModel | |
- (void)myMethod; | |
@end | |
@implementation MyViewModel | |
- (void)myMethod {} | |
@end | |
// --------------------------------------------------------------------------------------------------------------------- | |
@interface MyViewController : BaseViewController<MyViewModel *> | |
@end | |
@implementation MyViewController | |
- (void)yo { | |
[self.viewModel baseMethod]; | |
[self.viewModel myMethod]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment