AtSugarMixin 0.1.0

AtSugarMixin 0.1.0

TestsTested
LangLanguage Obj-CObjective C
License Custom
ReleasedLast Release Sep 2015

Maintained by Dustin Bachrach.



  • By
  • Dustin Bachrach

AtSugarMixin extends AtSugar to easily uses Mixins. Mixin functionality is provided by ObjectiveMixin.

Installation

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.

Author

MediaHound

License

AtSugarMixin is available under the Apache License 2.0. See the LICENSE file for more info.