Permalink
Browse files

Updated _printStorage method to actually print the property values

  • Loading branch information...
1 parent c042bc2 commit 54a6d7f7126a25bb013647b116e9f1f26cde2e56 @davedelong committed May 5, 2011
Showing with 12 additions and 3 deletions.
  1. +12 −3 DynamicStorage/DynamicStorage/DDDynamicStorageObject.m
@@ -9,6 +9,8 @@
#import "DDDynamicStorageObject.h"
#import <objc/runtime.h>
+static char valueKey = 1;
+
@implementation DDDynamicStorageObject
- (id)init {
@@ -26,7 +28,16 @@ - (NSMutableDictionary *)storage {
return _storage;
}
- (void)_printStorage {
- NSLog(@"%@", _storage);
+ NSMutableDictionary *tmpStorage = [NSMutableDictionary dictionaryWithCapacity:[_storage count]];
+ for (NSString *propertyName in _storage) {
+ NSObject *objectHolder = [_storage objectForKey:propertyName];
+ id propertyValue = objc_getAssociatedObject(objectHolder, &valueKey);
+ if (propertyValue == nil) {
+ propertyValue = [NSNull null];
+ }
+ [tmpStorage setObject:propertyValue forKey:propertyName];
+ }
+ NSLog(@"%@", tmpStorage);
}
+ (BOOL)resolveInstanceMethod:(SEL)sel {
@@ -119,8 +130,6 @@ + (BOOL)resolveInstanceMethod:(SEL)sel {
setterName = [NSString stringWithFormat:@"set%c%s:", toupper(rawPropertyName[0]), (rawPropertyName+1)];
}
- static char valueKey = 1;
-
id(^getterBlock)(id) = ^id(id _s) {
NSObject *v = [[_s storage] objectForKey:propertyName];
return objc_getAssociatedObject(v, &valueKey);

0 comments on commit 54a6d7f

Please sign in to comment.