1
0
mirror of https://github.com/danog/Telegram.git synced 2024-12-02 09:27:55 +01:00
Telegram/Telegraph/TGHolderSet.m
2016-02-25 01:03:51 +01:00

64 lines
1.0 KiB
Objective-C

#import "TGHolderSet.h"
@interface TGHolder ()
@end
@implementation TGHolder
@end
@interface TGHolderSet ()
{
NSMutableArray *_holders;
}
@end
@implementation TGHolderSet
- (instancetype)init
{
self = [super init];
if (self != nil)
{
_holders = [[NSMutableArray alloc] init];
}
return self;
}
- (void)addHolder:(TGHolder *)holder
{
TGDispatchOnMainThread(^
{
bool wasEmpty = _holders.count == 0;
if (![_holders containsObject:holder])
[_holders addObject:holder];
if (wasEmpty && _emptyStateChanged)
_emptyStateChanged(true);
});
}
- (void)removeHolder:(TGHolder *)holder
{
TGDispatchOnMainThread(^
{
bool becameEmpty = false;
if ([_holders containsObject:holder])
{
[_holders removeObject:holder];
becameEmpty = _holders.count == 0;
}
if (becameEmpty && _emptyStateChanged)
_emptyStateChanged(false);
});
}
- (bool)isEmpty {
return _holders.count == 0;
}
@end