AtSugarMixin extends AtSugar to easily uses Mixins. Mixin functionality is provided by ObjectiveMixin.
AtSugarMixin is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "AtSugarMixin"
Then include the header:
#import <AtSugarMixin/ASMixin.h>
First, declare a protocol for behavior implemented by a mixin. AtSugarMixin even allows you to mixin properties!
@protocol MyMixinProtocol <NSObject>
@property (strong, nonatomic) NSString* aStringProperty;
@property (strong, nonatomic) NSArray* anArrayProperty;
- (void)doSomething;
@end
You then create a class that will provide the mixin implementation. This class conforms to your mixin protocol.
#define MyMixinSynthesizeProperties aStringProperty, anArrayProperty
@interface MyMixin : NSObject <MYMixinProtocol>
@end
We need to define MyMixinSynthesizeProperties
so that that AtSugarMixin will synthesize the properties from the protocol.
@implementation MyMixin
@synthesize_from_mixin (MyMixin)
- (void)doSomething
{
// implementation
}
@end
Now we can mixin our MyMixin
behavior to any class we want.
@interface MyObject : NSObject <MyMixinProtocol>
@end
@implementation MyObject
@synthesize_from_mixin (MyMixin)
@end
Now MyObject
has 2 mixed in properties: aStringProperty
and anArrayProperty
. It also has a mixed in method: -doSomething
.
MediaHound
AtSugarMixin is available under the Apache License 2.0. See the LICENSE file for more info.