mirror of
https://github.com/GLEGram/GLEGram-iOS.git
synced 2026-04-26 12:56:34 +02:00
4647310322
Based on Swiftgram 12.5 (Telegram iOS 12.5). All GLEGram features ported and organized in GLEGram/ folder. Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass, Font Replacement, Fake Profile, Chat Export, Plugin System, and more. See CHANGELOG_12.5.md for full details.
65 lines
1.0 KiB
Objective-C
65 lines
1.0 KiB
Objective-C
#import "NSBag.h"
|
|
|
|
@interface NSBag ()
|
|
{
|
|
NSInteger _nextKey;
|
|
NSMutableArray *_items;
|
|
NSMutableArray *_itemKeys;
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation NSBag
|
|
|
|
- (instancetype)init
|
|
{
|
|
self = [super init];
|
|
if (self != nil)
|
|
{
|
|
_items = [[NSMutableArray alloc] init];
|
|
_itemKeys = [[NSMutableArray alloc] init];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (NSInteger)addItem:(id)item
|
|
{
|
|
if (item == nil)
|
|
return -1;
|
|
|
|
NSInteger key = _nextKey;
|
|
[_items addObject:item];
|
|
[_itemKeys addObject:@(key)];
|
|
_nextKey++;
|
|
|
|
return key;
|
|
}
|
|
|
|
- (void)enumerateItems:(void (^)(id))block
|
|
{
|
|
if (block)
|
|
{
|
|
for (id item in _items)
|
|
{
|
|
block(item);
|
|
}
|
|
}
|
|
}
|
|
|
|
- (void)removeItem:(NSInteger)key
|
|
{
|
|
NSUInteger index = 0;
|
|
for (NSNumber *itemKey in _itemKeys)
|
|
{
|
|
if ([itemKey integerValue] == key)
|
|
{
|
|
[_items removeObjectAtIndex:index];
|
|
[_itemKeys removeObjectAtIndex:index];
|
|
break;
|
|
}
|
|
index++;
|
|
}
|
|
}
|
|
|
|
@end
|