Skip to content

Instantly share code, notes, and snippets.

@leafduo
Last active December 12, 2015 09:48
Show Gist options
  • Select an option

  • Save leafduo/4753917 to your computer and use it in GitHub Desktop.

Select an option

Save leafduo/4753917 to your computer and use it in GitHub Desktop.
//
// main.m
// Foo
//
// Created by leafduo on 2/11/13.
// Copyright (c) 2013 leafduo.com. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "NSMutableArray+Pop.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSMutableArray *array = [@[@1, @2, @3] mutableCopy];
NSLog(@"%@", [array pop]);
NSLog(@"%@", array);
}
return 0;
}
//
// NSMutableArray+Pop.h
// Foo
//
// Created by leafduo on 2/11/13.
// Copyright (c) 2013 leafduo.com. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSMutableArray (Pop)
- (id)pop;
@end
//
// NSMutableArray+Pop.m
// Foo
//
// Created by leafduo on 2/11/13.
// Copyright (c) 2013 leafduo.com. All rights reserved.
//
#import "NSMutableArray+Pop.h"
@implementation NSMutableArray (Pop)
- (id)pop {
id obj = [self.lastObject copy];
[self removeObject:self.lastObject];
return obj;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment