Skip to content

Instantly share code, notes, and snippets.

@soxjke
Created March 15, 2017 20:56
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 soxjke/4051515865d098ec686b5afd2731554c to your computer and use it in GitHub Desktop.
Save soxjke/4051515865d098ec686b5afd2731554c to your computer and use it in GitHub Desktop.
NSObject+Cast
@interface NSObject (Cast)
+ (instancetype)cast:(id)object;
@end
#import "NSObject+Cast.h"
@implementation NSObject (Cast)
+ (instancetype)cast:(id)object {
return [object isKindOfClass:self] ? object : nil;
}
@end
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segueId isEqualToString:@"seagueAppointmentListToMap"]) {
HLJAppointment *appointment = [HLJAppointment cast:sender];
HLJAppointmentMapController *controller = [HLJAppointmentMapController cast:destinationController];
// property injection
controller.model = appointment;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment