Просмотр исходного кода

Detect and unbox pointers to objects from void *

- Also unbox C strings into NSString
- Also adds return type encoding string to method calling view controller
Tanner Bennett лет назад: 7
Родитель
Сommit
867ae614e5

+ 21 - 2
Classes/Editing/FLEXMethodCallingViewController.m

@@ -9,12 +9,15 @@
 #import "FLEXMethodCallingViewController.h"
 #import "FLEXRuntimeUtility.h"
 #import "FLEXFieldEditorView.h"
+#import "FLEXObjectExplorerFactory.h"
+#import "FLEXObjectExplorerViewController.h"
 #import "FLEXArgumentInputView.h"
 #import "FLEXArgumentInputViewFactory.h"
 
 @interface FLEXMethodCallingViewController ()
 
 @property (nonatomic, assign) Method method;
+@property (nonatomic, assign) FLEXTypeEncoding *returnType;
 
 @end
 
@@ -25,7 +28,8 @@
     self = [super initWithTarget:target];
     if (self) {
         self.method = method;
-        self.title = [self isClassMethod] ? @"Class Method" : @"Method";
+        self.returnType = [FLEXRuntimeUtility returnTypeForMethod:method];
+        self.title = [self isClassMethod] ? @"Class Method" : @"Method";;
     }
     return self;
 }
@@ -34,7 +38,11 @@
 {
     [super viewDidLoad];
     
-    self.fieldEditorView.fieldDescription = [FLEXRuntimeUtility prettyNameForMethod:self.method isClassMethod:[self isClassMethod]];
+    NSString *returnType = @((const char *)self.returnType);
+    NSString *methodDescription = [FLEXRuntimeUtility prettyNameForMethod:self.method isClassMethod:[self isClassMethod]];
+    NSString *format = @"Signature:\n%@\n\nReturn Type:\n%@";
+    NSString *info = [NSString stringWithFormat:format, methodDescription, returnType];
+    self.fieldEditorView.fieldDescription = info;
     
     NSArray<NSString *> *methodComponents = [FLEXRuntimeUtility prettyArgumentComponentsForMethod:self.method];
     NSMutableArray<FLEXArgumentInputView *> *argumentInputViews = [NSMutableArray array];
@@ -52,6 +60,12 @@
     self.fieldEditorView.argumentInputViews = argumentInputViews;
 }
 
+- (void)dealloc
+{
+    free(self.returnType);
+    self.returnType = NULL;
+}
+
 - (BOOL)isClassMethod
 {
     return self.target && self.target == [self.target class];
@@ -84,6 +98,11 @@
         NSString *message = [error localizedDescription];
         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
         [alert show];
+    } else if (returnedObject) {
+        // For non-nil (or void) return types, push an explorer view controller to display the returned object
+        returnedObject = [FLEXRuntimeUtility potentiallyUnwrapBoxedPointer:returnedObject type:self.returnType];
+        FLEXObjectExplorerViewController *explorerViewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:returnedObject];
+        [self.navigationController pushViewController:explorerViewController animated:YES];
     } else {
         [self exploreObjectOrPopViewController:returnedObject];
     }

+ 5 - 0
Classes/ObjectExplorers/FLEXObjectExplorerViewController.m

@@ -367,7 +367,10 @@ typedef NS_ENUM(NSUInteger, FLEXMetadataKind) {
     id value = nil;
     if ([self canHaveInstanceState]) {
         FLEXPropertyBox *propertyBox = self.filteredProperties[index];
+        NSString *typeString = [FLEXRuntimeUtility typeEncodingForProperty:propertyBox.property];
+        const FLEXTypeEncoding *encoding = [typeString cStringUsingEncoding:NSUTF8StringEncoding];
         value = [FLEXRuntimeUtility valueForProperty:propertyBox.property onObject:self.object];
+        value = [FLEXRuntimeUtility potentiallyUnwrapBoxedPointer:value type:encoding];
     }
     return value;
 }
@@ -449,7 +452,9 @@ typedef NS_ENUM(NSUInteger, FLEXMetadataKind) {
     id value = nil;
     if ([self canHaveInstanceState]) {
         FLEXIvarBox *ivarBox = self.filteredIvars[index];
+        const FLEXTypeEncoding *encoding = ivar_getTypeEncoding(ivarBox.ivar);
         value = [FLEXRuntimeUtility valueForIvar:ivarBox.ivar onObject:self.object];
+        value = [FLEXRuntimeUtility potentiallyUnwrapBoxedPointer:value type:encoding];
     }
     return value;
 }