.h
//
// LGQueue.h
// AntsSportApp
//
// Created by ligang on 15/3/24.
// Copyright (c) 2015年 ligang. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface LGQueue : NSObject
@property (nonatomic, strong) NSMutableArray *queue;
@property (nonatomic, readonly) NSInteger count;
- (void)enterQueue:(id)object;
- (id)exitQueue;
- (void)clear;
@end
.m
//
// LGQueue.m
// AntsSportApp
//
// Created by ligang on 15/3/24.
// Copyright (c) 2015年 ligang. All rights reserved.
//
#import "LGQueue.h"
@implementation LGQueue
- (id)init
{
if ( self = [super init] ) {
self.queue = [[NSMutableArray alloc] init];
_count = 0;
}
return self;
}
- (void)enterQueue:(id)object
{
[self.queue addObject:object];
_count = self.queue.count;
}
- (id)exitQueue
{
if ( self.queue.count == 0 ) return nil;
id object = [self.queue objectAtIndex:0];
[self.queue removeObjectAtIndex:0];
_count = self.queue.count;
return object;
}
- (void)clear
{
[self.queue removeAllObjects];
_count = 0;
}
@end
本文出处刚刚在线:http://www.superqq.com/blog/2015/03/24/zi-ji-dong-shou-chuang-jian-%5B%3F%5D-ge-dui-lie-lgqueue/