-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d90a1c
commit fc4cbf6
Showing
16 changed files
with
459 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// TyphoonComponentsPool.h | ||
// A-Typhoon | ||
// | ||
// Created by Aleksey Garbarev on 29.01.14. | ||
// Copyright (c) 2014 Jasper Blues. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
/** Methods from NSMutableDictionary which used in componentsPool. Created to maintain custom TyphoonWeekComponentsPool */ | ||
|
||
@protocol TyphoonComponentsPool <NSObject> | ||
|
||
- (void) setObject:(id)object forKey:(id<NSCopying>)aKey; | ||
- (id) objectForKey:(id<NSCopying>)aKey; | ||
|
||
- (NSArray *) allValues; | ||
|
||
- (void) removeAllObjects; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// TyphoonWeekComponentsPool.h | ||
// A-Typhoon | ||
// | ||
// Created by Aleksey Garbarev on 29.01.14. | ||
// Copyright (c) 2014 Jasper Blues. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "TyphoonComponentsPool.h" | ||
|
||
@interface TyphoonWeekComponentsPool : NSObject <TyphoonComponentsPool> | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// TyphoonWeekComponentsPool.m | ||
// A-Typhoon | ||
// | ||
// Created by Aleksey Garbarev on 29.01.14. | ||
// Copyright (c) 2014 Jasper Blues. All rights reserved. | ||
// | ||
|
||
#import "TyphoonWeekComponentsPool.h" | ||
#import "NSObject+DeallocNotification.h" | ||
|
||
@implementation TyphoonWeekComponentsPool { | ||
NSMutableDictionary *dictionaryWithUnretainedObjects; | ||
} | ||
|
||
- (id)init | ||
{ | ||
self = [super init]; | ||
if (self) { | ||
CFDictionaryValueCallBacks callbacks = {0, NULL, NULL, NULL, NULL}; | ||
dictionaryWithUnretainedObjects = (__bridge_transfer id)CFDictionaryCreateMutable(NULL, | ||
0, | ||
&kCFTypeDictionaryKeyCallBacks, | ||
&callbacks); | ||
} | ||
return self; | ||
} | ||
|
||
- (void) setObject:(id)object forKey:(id<NSCopying>)aKey | ||
{ | ||
__weak typeof (dictionaryWithUnretainedObjects) weakDict = dictionaryWithUnretainedObjects; | ||
|
||
[object setDeallocNotificationInBlock:^{ | ||
[weakDict removeObjectForKey:aKey]; | ||
}]; | ||
|
||
[dictionaryWithUnretainedObjects setObject:object forKey:aKey]; | ||
} | ||
|
||
- (id) objectForKey:(id<NSCopying>)aKey | ||
{ | ||
return [dictionaryWithUnretainedObjects objectForKey:aKey]; | ||
} | ||
|
||
- (NSArray *) allValues | ||
{ | ||
return [dictionaryWithUnretainedObjects allValues]; | ||
} | ||
|
||
- (void) removeAllObjects | ||
{ | ||
[dictionaryWithUnretainedObjects removeAllObjects]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.