Skip to content

Instantly share code, notes, and snippets.

@ivanacostarubio
Forked from afrael/protocolDemo.m
Last active December 21, 2015 12:58
Show Gist options
  • Save ivanacostarubio/6308946 to your computer and use it in GitHub Desktop.
Save ivanacostarubio/6308946 to your computer and use it in GitHub Desktop.
// Model
// OAStack.m
@protocol OAStack
- (void) pushData:(id)data;
- (id) popData;
@optional
- (void) purgeStack;
@end
// Model
// OAStackWithArray.m
@implementation OAStackWithArray : NSObject <OAStack>
@property (nonatomic, strong) NSMutableArray *containerArray;
@property (nonatomic, assign) NSUInteger currentIndex;
- (id)init
{
self = [[super alloc] init];
if(self){
self.containerArray = [NSMutableArray array];
self.currentIndex = 0;
}
return self;
}
- (void) pushData:(id)data
{
self.containerArray[self.currentIndex] = data;
self.currentIndex++;
}
- (id) popData
{
NSUInteger idx = self.currentIndex;
self.currentIndex--;
self.currentIndex = self.currentIndex < 0 ? 0 : self.currentIndex;
return self.cointainerArray[idx];
}
@end
// Model
// OAStackHelper.m
@implementation OAStackHelper : NSObject
def stack
@stack ||= OAStackWithArray.alloc.inic
end
def wrapper_push
@stack.push....
end
def wrapper_pop
@stack.pop ....
end
@end
// Controller
// OAStackViewController.m
@implementation OAStackViewController : UIViewController
@property (nonatomic, strong) id<OAStack> stack;
- (void) viewDidLoad
{
self.stack = [[OAStackHelper alloc] init];
}
- (IBAction) pushDataToStack:(id)sender
{
UIButton *addButton = (UIButton*)sender;
[self.stack wrapper_push:addButton.tag];
}
- (IBAction) popDataFromStack:(id)sender
{
id data = [self.stack wrapper_pop];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment