Protocol extension for Objective-C
Objective-C
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ProtocolKit.xcodeproj Initial Sep 2, 2015
ProtocolKit
.gitignore Initial commit Sep 2, 2015
LICENSE
README.md Update README.md Sep 2, 2015

README.md

ProtocolKit

Protocol extension for Objective-C

Usage

Your protocol:

@protocol Forkable <NSObject>

@optional
- (void)fork;

@required
- (NSString *)github;

@end

Protocol extension, add default implementation, use @defs magic keyword

@defs(Forkable)

- (void)fork {
    NSLog(@"Forkable protocol extension: I'm forking (%@).", self.github);
}

- (NSString *)github {
    return @"This is a required method, concrete class must override me.";
}

@end

Your concrete class

@interface Forkingdog : NSObject <Forkable>
@end

@implementation Forkingdog

- (NSString *)github {
    return @"https://github.com/forkingdog";
}

@end

Run test

[[Forkingdog new] fork];

Result

[Console] Forkable protocol extension: I'm forking (https://github.com/forkingdog).