测试已测试 | ✓ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最新发布 | 2014年12月 |
由Tobias Sundstrand,Tobias Sundstand维护。
TSCollections是一组表示常用集合模式的便利类。例如栈或队列。
使用CocoaPods,或将所需的源文件拖动到您的项目中。
获取所有集合。
pod 'TSCollections'
或特定集合
pod 'TSCollections/TSQueue'
TSStack是线程安全栈(先进后出)的实现。您可以从栈中执行所有预期的操作,例如推、弹和查看。例如
[stack push:@1]; //Pushes an object onto the stack.
id object = [stack pop]; //Removes the object an returns it.
id object = [stack peek]; //Only looks at the last item, does not remove it.
NSUInteger count = stack.count;
TSQueue是线程安全队列(先进先出)的实现。它可以用于按顺序队列和去队列项目。例如
[queue enqueue:@1]; //Enqueues an object in the queue.
id object = [queue dequeue]; //Removes the first object in the queue and returns it.
id object = [queue peek]; //Look at the first object in the queue and returns it.
NSUInteger count = queue.count;
TSExpandingArray是一个数组实现,您可以在任意索引处设置一个对象,如果索引超出范围,则数组将扩展并返回一个您设置的“fillout”类的对象。默认填充类是NSNull,但您可以设置任何需要的类。
TSExpandingArray *arr = [[TSExpandingArray alloc] initWithSize:5]; //Creates an array with 5 NSNull objects.
TSExpandingArray *arr = [[TSExpandingArray alloc] initWithSize:2 fillOutClass:[TSExpandingArray class];
//Creates an array with two TSExpandingArrays in it.
arr[17] = @13 //Will expand the array to 18 in size and set 13 as the last object
arr[19] //Will return the element at index 19, if the array is smaller the array will expand to size 20.
TSTwoDimensionalArray是一个数组实现,允许您为一个任意的行和列设置一个对象。TSTwoDimensionalArray使用TSExpandingArray,因此在设置或检索对象时将根据需要扩展。
[array setObject:@1 atRow:54 column:12]; //Sets an object at a specific row and column
id obj = [array objectAtRow:2 column:4]; //Returns the object at the coordinate 2,4 or NSNull if there is no object there.
array[12][2] = @145 //Sets an object at coordiante 12,2
id obj = array[90][90] //Gets the object at coordinate 90,90 or NSNull if there is no object there.
TSExpandingArray *row = array[12]; //Returns row 12.
TSExpandingArray *column = [array objectsAtColumn:12] //Returns column 12.