NSMutableArray *queue = [NSMutableArray new]; id firstItem = [queue objectAtIndex:0]; id lastItem = [queue objectAtIndex:queue.count-1];
在iOS7中NSArray新添了两个方法来得到首尾元素:
id firstItem = [queue firstObject]; id lastItem = [queue lastObject];
NSMutableArray *queue = [NSMutableArray new]; id firstItem = [queue objectAtIndex:0]; id lastItem = [queue objectAtIndex:queue.count-1];
id firstItem = [queue firstObject]; id lastItem = [queue lastObject];