Created
February 3, 2013 01:55
-
-
Save kristate/4700233 to your computer and use it in GitHub Desktop.
NSMapTableは本当に面倒いなー。C++は嫌なんやけど、この場合には std::map は良さげ。
This file contains hidden or 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
/* | |
* How to use std::map instead of NSMapTable -- assuming ARC | |
* Objective-C++はクレージーしすぎる件w まあいいか。 | |
* License: Public-Domain | |
*/ | |
#ifdef __cplusplus | |
#include <map> | |
#endif | |
@interface MyAwesomeController(Private) { | |
@private | |
#ifdef __cplusplus | |
std::map<uint64_t,id> *userCacheMap; | |
#else | |
#warning This is no time for you, Objective-C... | |
void *userCacheMap; | |
#endif | |
} | |
@end | |
@implementation MyAwesomeController | |
- (id)init { | |
if ((self = [super init])) { | |
userCacheMap = new std::map<uint64_t,id>; | |
} | |
return self; | |
} | |
- (MyAwesomeUserObj *) getUserFromUID: (uint64_t)uid { | |
return (*userCacheMap)[uid]; | |
} | |
- (void) setUserWithUID: (uint64_t)uid userObject: userobj { | |
(*userCacheMap)[uid] = (id)userobj; | |
return; | |
} | |
- (void) dealloc { | |
delete userCacheMap; | |
userCacheMap = NULL; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment