Skip to content

Instantly share code, notes, and snippets.

@kristate
Created February 3, 2013 01:55
Show Gist options
  • Save kristate/4700233 to your computer and use it in GitHub Desktop.
Save kristate/4700233 to your computer and use it in GitHub Desktop.
NSMapTableは本当に面倒いなー。C++は嫌なんやけど、この場合には std::map は良さげ。
/*
* 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