Explorar el Código

Truncate object descriptions to 10000 characters

Also fix description sizing bug
Tanner Bennett hace 6 años
padre
commit
0265334976

+ 1 - 1
Classes/Core/Views/Cells/FLEXMultilineTableViewCell.m

@@ -26,7 +26,7 @@
 }
 
 + (UIEdgeInsets)labelInsets {
-    return UIEdgeInsetsMake(10.0, 15.0, 10.0, 15.0);
+    return UIEdgeInsetsMake(10.0, 16.0, 10.0, 8.0);
 }
 
 + (CGFloat)preferredHeightWithAttributedText:(NSAttributedString *)attributedText

+ 26 - 16
Classes/ObjectExplorers/FLEXObjectExplorer.m

@@ -26,6 +26,7 @@
     NSMutableArray<NSArray<FLEXProtocol *> *> *_allConformedProtocols;
     NSMutableArray<FLEXStaticMetadata *> *_allInstanceSizes;
     NSMutableArray<FLEXStaticMetadata *> *_allImageNames;
+    NSString *_objectDescription;
 }
 @end
 
@@ -55,26 +56,34 @@
 #pragma mark - Public
 
 - (NSString *)objectDescription {
-    // Hard-code UIColor description
-    if ([self.object isKindOfClass:[UIColor class]]) {
-        CGFloat h, s, l, r, g, b, a;
-        [self.object getRed:&r green:&g blue:&b alpha:&a];
-        [self.object getHue:&h saturation:&s brightness:&l alpha:nil];
-
-        return [NSString stringWithFormat:
-            @"HSL: (%.3f, %.3f, %.3f)\nRGB: (%.3f, %.3f, %.3f)\nAlpha: %.3f",
-            h, s, l, r, g, b, a
-        ];
-    }
+    if (!_objectDescription) {
+        // Hard-code UIColor description
+        if ([self.object isKindOfClass:[UIColor class]]) {
+            CGFloat h, s, l, r, g, b, a;
+            [self.object getRed:&r green:&g blue:&b alpha:&a];
+            [self.object getHue:&h saturation:&s brightness:&l alpha:nil];
+
+            return [NSString stringWithFormat:
+                @"HSL: (%.3f, %.3f, %.3f)\nRGB: (%.3f, %.3f, %.3f)\nAlpha: %.3f",
+                h, s, l, r, g, b, a
+            ];
+        }
+
+        NSString *description = [FLEXRuntimeUtility safeDescriptionForObject:self.object];
 
-    NSString *description = [FLEXRuntimeUtility safeDescriptionForObject:self.object];
+        if (!description.length) {
+            NSString *address = [FLEXUtility addressOfObject:self.object];
+            return [NSString stringWithFormat:@"Object at %@ returned empty description", address];
+        }
+        
+        if (description.length > 10000) {
+            description = [description substringToIndex:10000];
+        }
 
-    if (!description.length) {
-        NSString *address = [FLEXUtility addressOfObject:self.object];
-        return [NSString stringWithFormat:@"Object at %@ returned empty description", address];
+        _objectDescription = description;
     }
 
-    return description;
+    return _objectDescription;
 }
 
 - (void)setClassScope:(NSInteger)classScope {
@@ -92,6 +101,7 @@
     _allConformedProtocols = [NSMutableArray new];
     _allInstanceSizes = [NSMutableArray new];
     _allImageNames = [NSMutableArray new];
+    _objectDescription = nil;
 
     [self reloadClassHierarchy];
     

+ 4 - 4
Classes/ObjectExplorers/FLEXObjectExplorerViewController.m

@@ -162,10 +162,10 @@
     // Description section is only for instances
     if (self.explorer.objectIsInstance) {
         _descriptionSection = [FLEXSingleRowSection
-             title:@"Description" reuse:kFLEXMultilineCell cell:^(FLEXTableViewCell *cell) {
-                 cell.titleLabel.font = UIFont.flex_defaultTableCellFont;
-                 cell.titleLabel.text = explorer.objectDescription;
-             }
+            title:@"Description" reuse:kFLEXMultilineCell cell:^(FLEXTableViewCell *cell) {
+                cell.titleLabel.font = UIFont.flex_defaultTableCellFont;
+                cell.titleLabel.text = explorer.objectDescription;
+            }
         ];
         self.descriptionSection.filterMatcher = ^BOOL(NSString *filterText) {
             return [explorer.objectDescription localizedCaseInsensitiveContainsString:filterText];