-
-
Save ivanacostarubio/6308946 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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