Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement for some struct values.

  • Loading branch information...
commit 7f97dcae347e77f2a308733c36aae94918aed43f 1 parent aba6f63
@kishikawakatsumi authored
View
52 Classes/DescriptionBuilder.m
@@ -106,18 +106,21 @@ + (NSString *)reflectDescription:(id)obj style:(DescriptionStyle)style {
switch(*ivar_type) {
case '@':
object_getInstanceVariable(obj, ivar_name, (void **)&objValue);
-
if (!objValue) {
[description appendFormat:@"%@", [NSNull null]];
- } else if ([objValue respondsToSelector:@selector(description)]) {
+ break;
+ }
+ if ([objValue respondsToSelector:@selector(description)]) {
NSString *type = [NSString stringWithUTF8String:ivar_type];
- NSString *className = [type substringWithRange:NSMakeRange(2, [type length] - 3)];
- Class ivarClass = NSClassFromString(className);
- if ([NSString isSubclassOfClass:ivarClass]) {
- [description appendFormat:@"\"%@\"", [objValue description]];
- } else {
- [description appendFormat:@"%@", [objValue description]];
+ if ([type length] > 3) {
+ NSString *className = [type substringWithRange:NSMakeRange(2, [type length] - 3)];
+ Class ivarClass = NSClassFromString(className);
+ if ([NSString isSubclassOfClass:ivarClass]) {
+ [description appendFormat:@"\"%@\"", [objValue description]];
+ break;
+ }
}
+ [description appendFormat:@"%@", [objValue description]];
} else {
[description appendFormat:@"<%s: 0x%x>", class_getName([objValue class]), [objValue hash]];
}
@@ -190,8 +193,39 @@ + (NSString *)reflectDescription:(id)obj style:(DescriptionStyle)style {
object_getInstanceVariable(obj, ivar_name, (void **)&voidPtrValue);
[description appendFormat:@"%p", voidPtrValue];
break;
+ case '{':
+ {
+ NSString *type = [NSString stringWithUTF8String:ivar_type];
+ NSString *structName = [type substringWithRange:NSMakeRange(1, [type rangeOfString:@"="].location - 1)];
+ if ([structName isEqualToString:@"CGAffineTransform"]) {
+ CGAffineTransform transform;
+ object_getInstanceVariable(obj, ivar_name, (void **)&transform);
+ [description appendFormat:@"%@", NSStringFromCGAffineTransform(transform)];
+ } else if ([structName isEqualToString:@"CGPoint"]) {
+ CGPoint point;
+ object_getInstanceVariable(obj, ivar_name, (void **)&point);
+ [description appendFormat:@"%@", NSStringFromCGPoint(point)];
+ } else if ([structName isEqualToString:@"CGRect"]) {
+ CGRect rect;
+ object_getInstanceVariable(obj, ivar_name, (void **)&rect);
+ [description appendFormat:@"%@", NSStringFromCGRect(rect)];
+ } else if ([structName isEqualToString:@"CGSize"]) {
+ CGSize size;
+ object_getInstanceVariable(obj, ivar_name, (void **)&size);
+ [description appendFormat:@"%@", NSStringFromCGSize(size)];
+ } else if ([structName isEqualToString:@"_NSRange"]) {
+ NSRange range;
+ object_getInstanceVariable(obj, ivar_name, (void **)&range);
+ [description appendFormat:@"%@", NSStringFromRange(range)];
+ } else if ([structName isEqualToString:@"UIEdgeInsets"]) {
+ UIEdgeInsets insets;
+ object_getInstanceVariable(obj, ivar_name, (void **)&insets);
+ [description appendFormat:@"%@", NSStringFromUIEdgeInsets(insets)];
+ }
+ break;
+ }
default:
- [description appendFormat:@"%s", ivar_type]; // TODO
+ [description appendFormat:@"%s", ivar_type];
break;
}
}
View
6 Classes/DescriptionBuilderAppDelegate.m
@@ -7,15 +7,15 @@
//
#import "DescriptionBuilderAppDelegate.h"
-#import "Settings.h"
+#import "TestObject.h"
@implementation DescriptionBuilderAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
- Settings *settings = [Settings sharedSettings];
- NSLog(@"%@", settings);
+ TestObject *object = [TestObject sharedObject];
+ NSLog(@"%@", object);
[window makeKeyAndVisible];
}
View
27 Classes/TestObject.h
@@ -0,0 +1,27 @@
+//
+// TestObject.h
+// DescriptionBuilder
+//
+// Created by KISHIKAWA Katsumi on 09/09/07.
+// Copyright KISHIKAWA Katsumi 2009. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface TestObject : NSObject {
+ NSUInteger version;
+ BOOL autoLock;
+ BOOL twentyFourHourTime;
+ NSString *alarmSound;
+ float alarmVolume;
+}
+
+@property (nonatomic) NSUInteger version;
+@property (nonatomic) BOOL autoLock;
+@property (nonatomic) BOOL twentyFourHourTime;
+@property (nonatomic, retain) NSString *alarmSound;
+@property (nonatomic) float alarmVolume;
+
++ (TestObject *)sharedObject;
+
+@end
View
49 Classes/TestObject.m
@@ -0,0 +1,49 @@
+//
+// Settings.m
+// DescriptionBuilder
+//
+// Created by KISHIKAWA Katsumi on 09/09/07.
+// Copyright KISHIKAWA Katsumi 2009. All rights reserved.
+//
+
+#import "TestObject.h"
+#import "DescriptionBuilder.h"
+
+@implementation TestObject
+
+static TestObject *sharedObject;
+
+@synthesize version;
+@synthesize autoLock;
+@synthesize twentyFourHourTime;
+@synthesize alarmSound;
+@synthesize alarmVolume;
+
++ (TestObject *)sharedObject {
+ if (!sharedObject) {
+ sharedObject = [[TestObject alloc] init];
+ }
+ return sharedObject;
+}
+
+- (id)init {
+ if (self = [super init]) {
+ version = 100;
+ autoLock = NO;
+ twentyFourHourTime = YES;
+ self.alarmSound = @"digital-alarm";
+ alarmVolume = 1.0f;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [alarmSound release];
+ [super dealloc];
+}
+
+- (NSString *)description {
+ return [DescriptionBuilder reflectDescription:self];
+}
+
+@end
View
12 DescriptionBuilder.xcodeproj/project.pbxproj
@@ -8,7 +8,7 @@
/* Begin PBXBuildFile section */
14F51B9610542E1D0076631A /* DescriptionBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 14F51B9510542E1D0076631A /* DescriptionBuilder.m */; };
- 14F51DBC105456E00076631A /* Settings.m in Sources */ = {isa = PBXBuildFile; fileRef = 14F51DBB105456E00076631A /* Settings.m */; };
+ 14F51DBC105456E00076631A /* TestObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 14F51DBB105456E00076631A /* TestObject.m */; };
1D3623260D0F684500981E51 /* DescriptionBuilderAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D3623250D0F684500981E51 /* DescriptionBuilderAppDelegate.m */; };
1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; };
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
@@ -20,8 +20,8 @@
/* Begin PBXFileReference section */
14F51B9410542E1D0076631A /* DescriptionBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DescriptionBuilder.h; sourceTree = "<group>"; };
14F51B9510542E1D0076631A /* DescriptionBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DescriptionBuilder.m; sourceTree = "<group>"; };
- 14F51DBA105456E00076631A /* Settings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Settings.h; sourceTree = "<group>"; };
- 14F51DBB105456E00076631A /* Settings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Settings.m; sourceTree = "<group>"; };
+ 14F51DBA105456E00076631A /* TestObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestObject.h; sourceTree = "<group>"; };
+ 14F51DBB105456E00076631A /* TestObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestObject.m; sourceTree = "<group>"; };
1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
1D3623240D0F684500981E51 /* DescriptionBuilderAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DescriptionBuilderAppDelegate.h; sourceTree = "<group>"; };
1D3623250D0F684500981E51 /* DescriptionBuilderAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DescriptionBuilderAppDelegate.m; sourceTree = "<group>"; };
@@ -54,8 +54,8 @@
14F51EB610546C5C0076631A /* lib */,
1D3623240D0F684500981E51 /* DescriptionBuilderAppDelegate.h */,
1D3623250D0F684500981E51 /* DescriptionBuilderAppDelegate.m */,
- 14F51DBA105456E00076631A /* Settings.h */,
- 14F51DBB105456E00076631A /* Settings.m */,
+ 14F51DBA105456E00076631A /* TestObject.h */,
+ 14F51DBB105456E00076631A /* TestObject.m */,
);
path = Classes;
sourceTree = "<group>";
@@ -173,7 +173,7 @@
1D60589B0D05DD56006BFB54 /* main.m in Sources */,
1D3623260D0F684500981E51 /* DescriptionBuilderAppDelegate.m in Sources */,
14F51B9610542E1D0076631A /* DescriptionBuilder.m in Sources */,
- 14F51DBC105456E00076631A /* Settings.m in Sources */,
+ 14F51DBC105456E00076631A /* TestObject.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Please sign in to comment.
Something went wrong with that request. Please try again.