/
BirdLeon
/
ROBLOX2016
Обзор
Документация
Войти
/
BirdLeon
/
ROBLOX2016
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
iOS/RobloxUI/Source/Components/RobloxImageCache.m
63 строки
1 KB
PatoFlamejanteTV
full source code
19 дек 2024, 19:11
19 дек 2024, 19:11
05db15d
Код
Авторство
О чём код?
// // RobloxCache.m // RobloxMobile // // Created by Ariel Lichtin on 8/29/14. // Copyright (c) 2014 ROBLOX. All rights reserved. // #import "RobloxImageCache.h" #import "RobloxNotifications.h" @implementation RobloxImageCache { NSCache* _memCache; } + (RobloxImageCache*) sharedInstance { static dispatch_once_t once; static id instance; dispatch_once(&once, ^ { instance = [self new]; }); return instance; } - (id)init { self = [super init]; if(self) { _memCache = [[NSCache alloc] init]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearMemory) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; } return self; } - (UIImage*) getImage:(NSString*)key size:(CGSize)size { return [_memCache objectForKey:key]; } - (void) setImage:(UIImage*)image key:(NSString*)key size:(CGSize)size { if(image == nil) { return; } [_memCache setObject:image forKey:key cost:(size.width * size.height)]; } - (void) clearMemory { [_memCache removeAllObjects]; } @end