Skip to content

Instantly share code, notes, and snippets.

@philosopherdog
Created April 29, 2015 20:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save philosopherdog/6461536b99ef73a5c32a to your computer and use it in GitHub Desktop.
Save philosopherdog/6461536b99ef73a5c32a to your computer and use it in GitHub Desktop.
External Class Extension Mimics Protected Members
//
// ClassA.h
// TestHeader
//
// Created by steve on 2015-04-29.
// Copyright (c) 2015 steve. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface ClassA : NSObject
@end
//
// ClassA.m
// TestHeader
//
// Created by steve on 2015-04-29.
// Copyright (c) 2015 steve. All rights reserved.
//
#import "ClassA.h"
#import "Test.h"
@implementation ClassA
- (void)testWithMessage:(NSString *)message
{
NSLog(@"%@", message);
}
@end
//
// ClassB.h
// TestHeader
//
// Created by steve on 2015-04-29.
// Copyright (c) 2015 steve. All rights reserved.
//
#import "ClassA.h"
@interface ClassB : ClassA
- (void)doIt;
@end
//
// ClassB.m
// TestHeader
//
// Created by steve on 2015-04-29.
// Copyright (c) 2015 steve. All rights reserved.
//
#import "ClassB.h"
#import "Test.h"
@implementation ClassB
- (void)doIt
{
[self testWithMessage:@"My message"];
}
@end
//
// main.m
// TestHeader
//
// Created by steve on 2015-04-29.
// Copyright (c) 2015 steve. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ClassB.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
ClassB *classB = [ClassB new];
[classB doIt];
}
return 0;
}
//
// Test.h
// TestHeader
//
// Created by steve on 2015-04-29.
// Copyright (c) 2015 steve. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface ClassA()
- (void)testWithMessage:(NSString *)message;
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment