Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/forkingdog/ProtocolKit

Protocol extension for Objective-C
https://github.com/forkingdog/ProtocolKit

Last synced: about 1 month ago
JSON representation

Protocol extension for Objective-C

Awesome Lists containing this project

README

        

# ProtocolKit
Protocol extension for Objective-C

# Usage

Your protocol:

``` objc

@protocol Forkable

@optional
- (void)fork;

@required
- (NSString *)github;

@end
```

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

``` objc

@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

``` objc
@interface Forkingdog : NSObject
@end

@implementation Forkingdog

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

@end
```

Run test

``` objc
[[Forkingdog new] fork];
```

Result

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