Compare commits

...

24 Commits

Author SHA1 Message Date
Tanner Bennett e89fec4b2d Bump version 2020-12-17 01:57:25 -06:00
Tanner Bennett 715bb92929 Add confirm dialog for clearing the keychain 2020-12-17 01:35:03 -06:00
Tanner Bennett 109074f98e Show service AND account in keychain rows 2020-12-17 01:34:44 -06:00
Tanner Bennett 45fbdb7914 Move keychain buttons to toolbar 2020-12-17 01:34:33 -06:00
Tanner Bennett cb2e0789d8 Fix several memory leaks, fix #483
Also move a bunch of globals related to FLEXShortcutsFactory into ivars of a FLEXShortcutsFactory singleton so that it is easier to trace the origin of the global storage of FLEX[Property|Ivar|Method] objects in a memory graph
2020-12-17 01:17:40 -06:00
vvveiii de1ca783b6 Fix flex_copy: crash when object is nil 2020-12-16 22:30:11 -08:00
vvveiii 3a9c24b784 Add missing else for flex_copy method 2020-12-16 22:30:11 -08:00
Tanner Bennett b57a333fc9 Fix #491, close #473
Remove (most) uses of +[NSString stringWithCString:encoding:]
2020-12-17 00:20:17 -06:00
matrush 288bf1343e Add ability to toggle bg color for image previews
Also fix availability warning
2020-12-15 16:35:27 -08:00
matrush a0b1caed54 Use UITableViewCellAccessoryNone instead of 0 in FLEX[Layer/View]Shortcuts 2020-12-14 18:38:04 -08:00
Tanner Bennett 9282c61183 Allow scrubbing between selected views
Instead of a singular swipe gesture to navigate between views in the view hierarchy at the tap point, we can now pan or drag along that same area to "srub" the hierarchy.
2020-12-14 18:36:44 -06:00
Tanner Bennett ee6677ee08 Add GUI shortcut for initializeWebKitLegacy
We call initializeWebKitLegacy automatically before you search all bundles just to be safe (since touching some classes before WebKit is initialized will initialize it on a thread other than the main thread), but sometimes you can encounter this crash without searching through all bundles, of course.

In this case, you can now long press on the navigation bar to call initializeWebKitLegacy
2020-12-14 17:10:48 -06:00
Tanner Bennett 3276eb3516 Automatically activate search bar in heap explorer
2f952c38 apparently didn't do this, oops
2020-12-14 17:10:48 -06:00
Chaoshuai Lü a3fa7bbadc Fix view/controller preview image issue (#493) 2020-12-14 16:08:58 -06:00
matrush 637074b354 Use id<NSCopying> as key instead of Class<NSCopying> in FLEXObjectExplorerFactory 2020-12-01 16:56:08 -08:00
Tanner Bennett 547bfbaec0 Disallow preview of views with no rect 2020-11-02 20:42:10 -06:00
Tanner Bennett 4e1fcf4682 Bump version, 4.2.2 2020-11-02 19:36:15 -06:00
Tanner Bennett 4d50fd2020 Revert "Use NSString as key …" in d7786449
We NEED to use the class as a key, because you cannot differentiate a class's name from the metaclass's name.
2020-11-02 19:36:15 -06:00
Tanner Bennett 2c510c8ca1 Fix log timer in example app not firing 2020-11-02 17:45:21 -06:00
Tanner Bennett 8283e2a8e7 Fix #415, restore ability to copy log messages 2020-11-02 17:32:29 -06:00
Tanner Bennett 3f82631a95 Fix bug introduced in 4.2.0, unable to edit members
Oopsie
2020-11-02 17:03:37 -06:00
matrush d77864494d Use NSString as key instead of Class<NSCopying> in FLEXObjectExplorerFactory 2020-11-02 16:58:59 -06:00
matrush c5ed6d4ece Add void to function definition of FLEXConstructorsShouldRun 2020-11-02 16:58:59 -06:00
matrush 9412f6eccf Add a clear global entries method for FLEXManager 2020-11-02 16:58:59 -06:00
26 changed files with 332 additions and 133 deletions
@@ -76,11 +76,11 @@ NSString * const kCarouselCellReuseIdentifier = @"kCarouselCellReuseIdentifier";
_dynamicTypeObserver = [NSNotificationCenter.defaultCenter
addObserverForName:UIContentSizeCategoryDidChangeNotification
object:nil queue:nil usingBlock:^(NSNotification *note) {
__typeof(self) self = weakSelf;
[self.collectionView setNeedsLayout];
[self setNeedsUpdateConstraints];
// Notify observers
__typeof(self) self = weakSelf;
for (void (^block)(FLEXScopeCarousel *) in self.dynamicTypeHandlers) {
block(self);
}
@@ -45,6 +45,9 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
/// Only valid while a toolbar drag pan gesture is in progress.
@property (nonatomic) CGRect toolbarFrameBeforeDragging;
/// Only valid while a selected view pan gesture is in progress.
@property (nonatomic) CGFloat selectedViewLastPanX;
/// Borders of all the visible views in the hierarchy at the selection point.
/// The keys are NSValues with the corresponding view (nonretained).
@property (nonatomic) NSDictionary<NSValue *, UIView *> *outlineViewsForVisibleViews;
@@ -58,6 +61,9 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
/// A colored transparent overlay to indicate that the view is selected.
@property (nonatomic) UIView *selectedViewOverlay;
/// Used to actuate changes in view selection on iOS 10+
@property (nonatomic, readonly) UISelectionFeedbackGenerator *selectionFBG API_AVAILABLE(ios(10.0));
/// self.view.window as a \c FLEXWindow
@property (nonatomic, readonly) FLEXWindow *window;
@@ -118,6 +124,11 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
self.movePanGR = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleMovePan:)];
self.movePanGR.enabled = self.currentMode == FLEXExplorerModeMove;
[self.view addGestureRecognizer:self.movePanGR];
// Feedback
if (@available(iOS 10.0, *)) {
_selectionFBG = [UISelectionFeedbackGenerator new];
}
}
- (void)viewWillAppear:(BOOL)animated {
@@ -450,16 +461,16 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
];
[toolbar.selectedViewDescriptionContainer addGestureRecognizer:self.detailsTapGR];
// Swipe gestures for selecting deeper / higher views at a point
UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc]
UIPanGestureRecognizer *leftSwipe = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:@selector(handleChangeViewAtPointGesture:)
];
UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer alloc]
initWithTarget:self action:@selector(handleChangeViewAtPointGesture:)
];
leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;
// UIPanGestureRecognizer *rightSwipe = [[UIPanGestureRecognizer alloc]
// initWithTarget:self action:@selector(handleChangeViewAtPointGesture:)
// ];
// leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
// rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;
[toolbar.selectedViewDescriptionContainer addGestureRecognizer:leftSwipe];
[toolbar.selectedViewDescriptionContainer addGestureRecognizer:rightSwipe];
// [toolbar.selectedViewDescriptionContainer addGestureRecognizer:rightSwipe];
// Long press gesture to present tabs manager
[toolbar.globalsItem addGestureRecognizer:[[UILongPressGestureRecognizer alloc]
@@ -598,19 +609,54 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
}
}
- (void)handleChangeViewAtPointGesture:(UISwipeGestureRecognizer *)sender {
- (void)handleChangeViewAtPointGesture:(UIPanGestureRecognizer *)sender {
NSInteger max = self.viewsAtTapPoint.count - 1;
NSInteger currentIdx = [self.viewsAtTapPoint indexOfObject:self.selectedView];
switch (sender.direction) {
case UISwipeGestureRecognizerDirectionLeft:
self.selectedView = self.viewsAtTapPoint[MIN(max, currentIdx + 1)];
break;
case UISwipeGestureRecognizerDirectionRight:
self.selectedView = self.viewsAtTapPoint[MAX(0, currentIdx - 1)];
CGFloat locationX = [sender locationInView:self.view].x;
// Track the pan gesture: every N points we move along the X axis,
// actuate some haptic feedback and move up or down the hierarchy.
// We only store the "last" location when we've met the threshold.
// We only change the view and actuate feedback if the view selection
// changes; that is, as long as we don't go outside or under the array.
switch (sender.state) {
case UIGestureRecognizerStateBegan: {
self.selectedViewLastPanX = locationX;
break;
}
case UIGestureRecognizerStateChanged: {
static CGFloat kNextLevelThreshold = 20.f;
CGFloat lastX = self.selectedViewLastPanX;
NSInteger newSelection = currentIdx;
// Left, go down the hierarchy
if (locationX < lastX && (lastX - locationX) >= kNextLevelThreshold) {
// Choose a new view index up to the max index
newSelection = MIN(max, currentIdx + 1);
self.selectedViewLastPanX = locationX;
}
// Right, go up the hierarchy
else if (lastX < locationX && (locationX - lastX) >= kNextLevelThreshold) {
// Choose a new view index down to the min index
newSelection = MAX(0, currentIdx - 1);
self.selectedViewLastPanX = locationX;
}
if (currentIdx != newSelection) {
self.selectedView = self.viewsAtTapPoint[newSelection];
[self actuateSelectionChangedFeedback];
}
default:
break;
}
default: break;
}
}
- (void)actuateSelectionChangedFeedback {
if (@available(iOS 10.0, *)) {
[self.selectionFBG selectionChanged];
}
}
@@ -45,6 +45,15 @@ static const NSInteger kFLEXLiveObjectsSortBySizeIndex = 2;
[self reloadTableData];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
dispatch_async(dispatch_get_main_queue(), ^{
// This doesn't work unless it's wrapped in this dispatch_async call
[self.searchController.searchBar becomeFirstResponder];
});
}
- (NSArray<NSString *> *)allClassNames {
return self.instanceCountsForClassNames.allKeys;
}
@@ -360,7 +360,9 @@ typedef NS_ENUM(NSUInteger, FLEXFileBrowserSortAttribute) {
#if FLEX_AT_LEAST_IOS13_SDK
- (UIContextMenuConfiguration *)tableView:(UITableView *)tableView contextMenuConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath point:(CGPoint)point __IOS_AVAILABLE(13.0) {
- (UIContextMenuConfiguration *)tableView:(UITableView *)tableView
contextMenuConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath
point:(CGPoint)point __IOS_AVAILABLE(13.0) {
__weak __typeof__(self) weakSelf = self;
return [UIContextMenuConfiguration configurationWithIdentifier:nil
previewProvider:nil
@@ -170,7 +170,7 @@
- (NSString *)password {
if (self.passwordData.length) {
return [NSString stringWithCString:self.passwordData.bytes encoding:NSUTF8StringEncoding];
return [[NSString alloc] initWithData:self.passwordData encoding:NSUTF8StringEncoding];
}
return nil;
@@ -30,10 +30,10 @@
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItems = @[
[UIBarButtonItem flex_systemItem:UIBarButtonSystemItemTrash target:self action:@selector(trashPressed:)],
[UIBarButtonItem flex_systemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPressed)],
];
[self addToolbarItems:@[
FLEXBarButtonItemSystem(Add, self, @selector(addPressed)),
[FLEXBarButtonItemSystem(Trash, self, @selector(trashPressed:)) flex_withTintColor:UIColor.redColor],
]];
[self reloadData];
}
@@ -43,14 +43,15 @@
cellConfiguration:^(__kindof FLEXTableViewCell *cell, NSDictionary *item, NSInteger row) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
id account = item[kFLEXKeychainAccountKey];
if ([account isKindOfClass:[NSString class]]) {
cell.textLabel.text = account;
id service = item[kFLEXKeychainWhereKey];
if ([service isKindOfClass:[NSString class]]) {
cell.textLabel.text = service;
cell.detailTextLabel.text = item[kFLEXKeychainAccountKey];
} else {
cell.textLabel.text = [NSString stringWithFormat:
@"[%@]\n\n%@",
NSStringFromClass([account class]),
[account description]
NSStringFromClass([service class]),
[service description]
];
}
} filterMatcher:^BOOL(NSString *filterText, NSDictionary *item) {
@@ -129,6 +130,18 @@
make.title(@"Clear Keychain");
make.message(@"This will remove all keychain items for this app.\n");
make.message(@"This action cannot be undone. Are you sure?");
make.button(@"Yes, clear the keychain").destructiveStyle().handler(^(NSArray *strings) {
[self confirmClearKeychain];
});
make.button(@"Cancel").cancelStyle();
} showFrom:self source:sender];
}
- (void)confirmClearKeychain {
[FLEXAlert makeAlert:^(FLEXAlert *make) {
make.title(@"ARE YOU SURE?");
make.message(@"This action CANNOT BE UNDONE.\nAre you sure you want to continue?\n");
make.message(@"If you're sure, scroll to confirm.");
make.button(@"Yes, clear the keychain").destructiveStyle().handler(^(NSArray *strings) {
for (id account in self.section.list) {
[self deleteItem:account];
@@ -136,8 +149,12 @@
[self reloadData];
});
make.button(@"Cancel"); make.button(@"Cancel"); make.button(@"Cancel"); make.button(@"Cancel");
make.button(@"Cancel"); make.button(@"Cancel"); make.button(@"Cancel"); make.button(@"Cancel");
make.button(@"Cancel"); make.button(@"Cancel"); make.button(@"Cancel"); make.button(@"Cancel");
make.button(@"Cancel"); make.button(@"Cancel"); make.button(@"Cancel"); make.button(@"Cancel");
make.button(@"Cancel").cancelStyle();
} showFrom:self source:sender];
} showFrom:self];
}
- (void)addPressed {
@@ -13,6 +13,7 @@
#import "FLEXTableView.h"
#import "FLEXObjectExplorerFactory.h"
#import "FLEXAlert.h"
#import "FLEXRuntimeClient.h"
@interface FLEXObjcRuntimeViewController () <FLEXKeyPathSearchControllerDelegate>
@@ -28,6 +29,20 @@
- (void)viewDidLoad {
[super viewDidLoad];
// Long press on navigation bar to initialize webkit legacy
//
// We call initializeWebKitLegacy automatically before you search
// all bundles just to be safe (since touching some classes before
// WebKit is initialized will initialize it on a thread other than
// the main thread), but sometimes you can encounter this crash
// without searching through all bundles, of course.
[self.navigationController.navigationBar addGestureRecognizer:[
[UILongPressGestureRecognizer alloc]
initWithTarget:[FLEXRuntimeClient class]
action:@selector(initializeWebKitLegacy)
]
];
// Search bar stuff, must be first because this creates self.searchController
self.showsSearchBar = YES;
self.showSearchBarInitially = YES;
@@ -265,8 +265,30 @@ static BOOL my_os_log_shim_enabled(void *addr) {
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
if (action == @selector(copy:)) {
// We usually only want to copy the log message itself, not any metadata associated with it.
UIPasteboard.generalPasteboard.string = self.logMessages.filteredList[indexPath.row].messageText;
UIPasteboard.generalPasteboard.string = self.logMessages.filteredList[indexPath.row].messageText ?: @"";
}
}
#if FLEX_AT_LEAST_IOS13_SDK
- (UIContextMenuConfiguration *)tableView:(UITableView *)tableView
contextMenuConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath
point:(CGPoint)point __IOS_AVAILABLE(13.0) {
__weak __typeof__(self) weakSelf = self;
return [UIContextMenuConfiguration configurationWithIdentifier:nil
previewProvider:nil
actionProvider:^UIMenu *(NSArray<UIMenuElement *> *suggestedActions) {
UIAction *copy = [UIAction actionWithTitle:@"Copy"
image:nil
identifier:@"Copy"
handler:^(__kindof UIAction *action) {
// We usually only want to copy the log message itself, not any metadata associated with it.
UIPasteboard.generalPasteboard.string = weakSelf.logMessages.filteredList[indexPath.row].messageText ?: @"";
}];
return [UIMenu menuWithTitle:@"" image:nil identifier:nil options:UIMenuOptionsDisplayInline children:@[copy]];
}];
}
#endif
@end
@@ -38,6 +38,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)registerGlobalEntryWithName:(NSString *)entryName
viewControllerFutureBlock:(UIViewController * (^)(void))viewControllerFutureBlock;
/// Removes all registered global entries.
- (void)clearGlobalEntries;
#pragma mark - Simulator Shortcuts
/// Simulator keyboard shortcuts are enabled by default.
+20 -15
View File
@@ -58,6 +58,11 @@
[self.userGlobalEntries addObject:entry];
}
- (void)clearGlobalEntries
{
[self.userGlobalEntries removeAllObjects];
}
#pragma mark - Simulator Shortcuts
@@ -95,60 +100,60 @@
[self registerDefaultSimulatorShortcutWithKey:@"f" modifiers:0 action:^{
[self toggleExplorer];
} description:@"Toggle FLEX toolbar"];
[self registerDefaultSimulatorShortcutWithKey:@"g" modifiers:0 action:^{
[self showExplorerIfNeeded];
[self.explorerViewController toggleMenuTool];
} description:@"Toggle FLEX globals menu"];
[self registerDefaultSimulatorShortcutWithKey:@"v" modifiers:0 action:^{
[self showExplorerIfNeeded];
[self.explorerViewController toggleViewsTool];
} description:@"Toggle view hierarchy menu"];
[self registerDefaultSimulatorShortcutWithKey:@"s" modifiers:0 action:^{
[self showExplorerIfNeeded];
[self.explorerViewController toggleSelectTool];
} description:@"Toggle select tool"];
[self registerDefaultSimulatorShortcutWithKey:@"m" modifiers:0 action:^{
[self showExplorerIfNeeded];
[self.explorerViewController toggleMoveTool];
} description:@"Toggle move tool"];
[self registerDefaultSimulatorShortcutWithKey:@"n" modifiers:0 action:^{
[self toggleTopViewControllerOfClass:[FLEXNetworkMITMViewController class]];
} description:@"Toggle network history view"];
// 't' is for testing: quickly present an object explorer for debugging
[self registerDefaultSimulatorShortcutWithKey:@"t" modifiers:0 action:^{
[self showExplorerIfNeeded];
[self.explorerViewController toggleToolWithViewControllerProvider:^UINavigationController *{
return [FLEXNavigationController withRootViewController:[FLEXObjectExplorerFactory
explorerViewControllerForObject:NSBundle.mainBundle
]];
} completion:nil];
} description:@"Present an object explorer for debugging"];
[self registerDefaultSimulatorShortcutWithKey:UIKeyInputDownArrow modifiers:0 action:^{
if (self.isHidden || ![self.explorerViewController handleDownArrowKeyPressed]) {
[self tryScrollDown];
}
} description:@"Cycle view selection\n\t\tMove view down\n\t\tScroll down"];
[self registerDefaultSimulatorShortcutWithKey:UIKeyInputUpArrow modifiers:0 action:^{
if (self.isHidden || ![self.explorerViewController handleUpArrowKeyPressed]) {
[self tryScrollUp];
}
} description:@"Cycle view selection\n\t\tMove view up\n\t\tScroll up"];
[self registerDefaultSimulatorShortcutWithKey:UIKeyInputRightArrow modifiers:0 action:^{
if (!self.isHidden) {
[self.explorerViewController handleRightArrowKeyPressed];
}
} description:@"Move selected view right"];
[self registerDefaultSimulatorShortcutWithKey:UIKeyInputLeftArrow modifiers:0 action:^{
if (self.isHidden) {
[self tryGoBack];
@@ -156,15 +161,15 @@
[self.explorerViewController handleLeftArrowKeyPressed];
}
} description:@"Move selected view left"];
[self registerDefaultSimulatorShortcutWithKey:@"?" modifiers:0 action:^{
[self toggleTopViewControllerOfClass:[FLEXKeyboardHelpViewController class]];
} description:@"Toggle (this) help menu"];
[self registerDefaultSimulatorShortcutWithKey:UIKeyInputEscape modifiers:0 action:^{
[[self.topViewController presentingViewController] dismissViewControllerAnimated:YES completion:nil];
} description:@"End editing text\n\t\tDismiss top view controller"];
[self registerDefaultSimulatorShortcutWithKey:@"o" modifiers:UIKeyModifierCommand|UIKeyModifierShift action:^{
[self toggleTopViewControllerOfClass:[FLEXFileBrowserController class]];
} description:@"Toggle file browser menu"];
@@ -183,7 +188,7 @@
if (@available(iOS 11, *)) {
return scrollView.adjustedContentInset;
}
return scrollView.contentInset;
}
+2 -1
View File
@@ -28,7 +28,8 @@
}
if (request.HTTPBody) {
[curlCommandString appendFormat:@"-d \'%@\'", [NSString stringWithCString:request.HTTPBody.bytes encoding:NSUTF8StringEncoding]];
NSString *body = [[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding];
[curlCommandString appendFormat:@"-d \'%@\'", body];
}
return curlCommandString;
@@ -426,7 +426,8 @@ typedef UIViewController *(^FLEXNetworkDetailRowSelectionFuture)(void);
if (transaction.cachedRequestBody.length > 0) {
NSString *contentType = [transaction.request valueForHTTPHeaderField:@"Content-Type"];
if ([contentType hasPrefix:@"application/x-www-form-urlencoded"]) {
NSString *bodyString = [NSString stringWithCString:[self postBodyDataForTransaction:transaction].bytes encoding:NSUTF8StringEncoding];
NSData *body = [self postBodyDataForTransaction:transaction];
NSString *bodyString = [[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding];
postBodySection.rows = [self networkDetailRowsFromQueryItems:[FLEXUtility itemsFromQueryString:bodyString]];
}
}
@@ -21,13 +21,21 @@
#import "FLEXUtility.h"
@implementation FLEXObjectExplorerFactory
static NSMutableDictionary<Class, Class> *classesToRegisteredSections = nil;
static NSMutableDictionary<id<NSCopying>, Class> *classesToRegisteredSections = nil;
+ (void)initialize {
if (self == [FLEXObjectExplorerFactory class]) {
#define ClassKey(name) (Class<NSCopying>)[name class]
#define ClassKeyByName(str) (Class<NSCopying>)NSClassFromString(@ #str)
#define MetaclassKey(meta) (Class<NSCopying>)object_getClass([meta class])
// DO NOT USE STRING KEYS HERE
// We NEED to use the class as a key, because we CANNOT
// differentiate a class's name from the metaclass's name.
// These mappings are per-class-object, not per-class-name.
//
// For example, if we used class names, this would result in
// the object explorer trying to render a color preview for
// the UIColor class object, which is not a color itself.
#define ClassKey(name) (id<NSCopying>)[name class]
#define ClassKeyByName(str) (id<NSCopying>)NSClassFromString(@ #str)
#define MetaclassKey(meta) (id<NSCopying>)object_getClass([meta class])
classesToRegisteredSections = [NSMutableDictionary dictionaryWithDictionary:@{
MetaclassKey(NSObject) : [FLEXClassShortcuts class],
ClassKey(NSArray) : [FLEXCollectionContentSection class],
@@ -67,7 +75,7 @@ static NSMutableDictionary<Class, Class> *classesToRegisteredSections = nil;
Class sectionClass = nil;
Class cls = object_getClass(object);
do {
sectionClass = classesToRegisteredSections[(Class<NSCopying>)cls];
sectionClass = classesToRegisteredSections[(id<NSCopying>)cls];
} while (!sectionClass && (cls = [cls superclass]));
if (!sectionClass) {
@@ -81,7 +89,7 @@ static NSMutableDictionary<Class, Class> *classesToRegisteredSections = nil;
}
+ (void)registerExplorerSection:(Class)explorerClass forClass:(Class)objectClass {
classesToRegisteredSections[(Class<NSCopying>)objectClass] = explorerClass;
classesToRegisteredSections[(id<NSCopying>)objectClass] = explorerClass;
}
#pragma mark - FLEXGlobalsEntry
@@ -176,7 +184,7 @@ static NSMutableDictionary<Class, Class> *classesToRegisteredSections = nil;
return [self explorerViewControllerForObject:NSThread.mainThread];
case FLEXGlobalsRowOperationQueue:
return [self explorerViewControllerForObject:NSOperationQueue.mainQueue];
case FLEXGlobalsRowKeyWindow:
return [FLEXObjectExplorerFactory
explorerViewControllerForObject:FLEXUtility.appKeyWindow
@@ -15,11 +15,11 @@
+ (instancetype)forObject:(CALayer *)layer {
return [self forObject:layer additionalRows:@[
[FLEXActionShortcut title:@"Preview Image" subtitle:nil
viewer:^UIViewController *(id layer) {
viewer:^UIViewController *(CALayer *layer) {
return [FLEXImagePreviewViewController previewForLayer:layer];
}
accessoryType:^UITableViewCellAccessoryType(id layer) {
return UITableViewCellAccessoryDisclosureIndicator;
accessoryType:^UITableViewCellAccessoryType(CALayer *layer) {
return CGRectIsEmpty(layer.bounds) ? UITableViewCellAccessoryNone : UITableViewCellAccessoryDisclosureIndicator;
}
]
]];
@@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
@optional
/// Called when the (i) button is pressed if the accessory type includes it
- (UIViewController *)editorWith:(id)object;
- (UIViewController *)editorWith:(id)object forSection:(FLEXTableViewSection *)section;
@end
@@ -201,10 +201,10 @@
- (void (^)(__kindof UIViewController *))didPressInfoButtonAction:(NSInteger)row {
id<FLEXShortcut> shortcut = self.shortcuts[row];
if ([shortcut respondsToSelector:@selector(editorWith:)]) {
if ([shortcut respondsToSelector:@selector(editorWith:forSection:)]) {
id object = self.object;
return ^(UIViewController *host) {
UIViewController *editor = [shortcut editorWith:object];
UIViewController *editor = [shortcut editorWith:object forSection:self];
[host.navigationController pushViewController:editor animated:YES];
};
}
@@ -255,31 +255,52 @@
}
@end
#define NewAndSet(ivar) ({ FLEXShortcutsFactory *r = [self new]; r->ivar = YES; r; })
#define NewAndSet(ivar) ({ FLEXShortcutsFactory *r = [self sharedFactory]; r->ivar = YES; r; })
#define SetIvar(ivar) ({ self->ivar = YES; self; })
#define SetParamBlock(ivar) ^(NSArray *p) { self->ivar = p; return self; }
@implementation FLEXShortcutsFactory
typedef NSMutableDictionary<Class, NSMutableArray<id<FLEXRuntimeMetadata>> *> RegistrationBuckets;
// Class buckets
static RegistrationBuckets *cProperties = nil;
static RegistrationBuckets *cIvars = nil;
static RegistrationBuckets *cMethods = nil;
// Metaclass buckets
static RegistrationBuckets *mProperties = nil;
static RegistrationBuckets *mMethods = nil;
+ (void)load {
cProperties = [NSMutableDictionary new];
cIvars = [NSMutableDictionary new];
cMethods = [NSMutableDictionary new];
@implementation FLEXShortcutsFactory {
// Class buckets
RegistrationBuckets *cProperties;
RegistrationBuckets *cIvars;
RegistrationBuckets *cMethods;
// Metaclass buckets
RegistrationBuckets *mProperties;
RegistrationBuckets *mMethods;
}
mProperties = [NSMutableDictionary new];
mMethods = [NSMutableDictionary new];
+ (instancetype)sharedFactory {
static FLEXShortcutsFactory *shared = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shared = [self new];
});
return shared;
}
- (id)init {
self = [super init];
if (self) {
cProperties = [NSMutableDictionary new];
cIvars = [NSMutableDictionary new];
cMethods = [NSMutableDictionary new];
mProperties = [NSMutableDictionary new];
mMethods = [NSMutableDictionary new];
}
return self;
}
+ (NSArray<id<FLEXRuntimeMetadata>> *)shortcutsForObjectOrClass:(id)objectOrClass {
return [[self sharedFactory] shortcutsForObjectOrClass:objectOrClass];
}
- (NSArray<id<FLEXRuntimeMetadata>> *)shortcutsForObjectOrClass:(id)objectOrClass {
NSMutableArray<id<FLEXRuntimeMetadata>> *shortcuts = [NSMutableArray new];
BOOL isClass = object_isClass(objectOrClass);
// The -class does not give you a metaclass, and we want a metaclass
@@ -325,30 +346,45 @@ static RegistrationBuckets *mMethods = nil;
}
- (void)_register:(NSArray<id<FLEXRuntimeMetadata>> *)items to:(RegistrationBuckets *)global class:(Class)key {
// Get (or initialize) the bucket for this class
NSMutableArray *bucket = ({
id bucket = global[key];
if (!bucket) {
bucket = [NSMutableArray new];
global[(id)key] = bucket;
}
bucket;
});
@synchronized (self) {
// Get (or initialize) the bucket for this class
NSMutableArray *bucket = ({
id bucket = global[key];
if (!bucket) {
bucket = [NSMutableArray new];
global[(id)key] = bucket;
}
bucket;
});
if (self->_append) { [bucket addObjectsFromArray:items]; }
if (self->_replace) { [bucket setArray:items]; }
if (self->_prepend) {
if (bucket.count) {
// Set new items as array, add old items behind them
id copy = bucket.copy;
[bucket setArray:items];
[bucket addObjectsFromArray:copy];
} else {
[bucket addObjectsFromArray:items];
if (self->_append) { [bucket addObjectsFromArray:items]; }
if (self->_replace) { [bucket setArray:items]; }
if (self->_prepend) {
if (bucket.count) {
// Set new items as array, add old items behind them
id copy = bucket.copy;
[bucket setArray:items];
[bucket addObjectsFromArray:copy];
} else {
[bucket addObjectsFromArray:items];
}
}
[self reset];
}
}
- (void)reset {
_append = NO;
_prepend = NO;
_replace = NO;
_notInstance = NO;
_properties = nil;
_ivars = nil;
_methods = nil;
}
- (FLEXShortcutsFactory *)class {
return SetIvar(_notInstance);
}
@@ -405,9 +441,15 @@ static RegistrationBuckets *mMethods = nil;
Class metaclass = isMeta ? cls : object_getClass(cls);
Class clsForMetadata = instanceMetadata ? cls : metaclass;
// The factory is a singleton so we don't need to worry about "leaking" it
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wimplicit-retain-self"
RegistrationBuckets *propertyBucket = instanceShortcut ? cProperties : mProperties;
RegistrationBuckets *methodBucket = instanceShortcut ? cMethods : mMethods;
RegistrationBuckets *ivarBucket = instanceShortcut ? cIvars : nil;
#pragma clang diagnostic pop
if (self->_properties) {
NSArray *items = [self->_properties flex_mapped:^id(NSString *name, NSUInteger idx) {
@@ -70,15 +70,18 @@
return [FLEXObjectExplorerFactory explorerViewControllerForObject:controller];
}
accessoryType:^UITableViewCellAccessoryType(id view) {
return controller ? UITableViewCellAccessoryDisclosureIndicator : 0;
return controller ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
}
],
[FLEXActionShortcut title:@"Preview Image" subtitle:nil
viewer:^UIViewController *(id view) {
[FLEXActionShortcut title:@"Preview Image" subtitle:^NSString *(UIView *view) {
return !CGRectIsEmpty(view.bounds) ? @"" : @"Unavailable with empty bounds";
}
viewer:^UIViewController *(UIView *view) {
return [FLEXImagePreviewViewController previewForView:view];
}
accessoryType:^UITableViewCellAccessoryType(id view) {
return UITableViewCellAccessoryDisclosureIndicator;
accessoryType:^UITableViewCellAccessoryType(UIView *view) {
// Disable preview if bounds are CGRectZero
return !CGRectIsEmpty(view.bounds) ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
}
]
]];
@@ -95,6 +95,7 @@ NSArray<FLEXProtocol *> *FLEXGetConformedProtocols(Class cls) {
unsigned int count = 0;
Protocol *__unsafe_unretained *list = class_copyProtocolList(cls, &count);
NSArray<Protocol *> *protocols = [NSArray arrayWithObjects:list count:count];
free(list);
return [protocols flex_mapped:^id(Protocol *pro, NSUInteger idx) {
return [FLEXProtocol protocol:pro];
@@ -11,16 +11,21 @@
@implementation UIPasteboard (FLEX)
- (void)flex_copy:(id)object {
if (!object) {
return;
}
if ([object isKindOfClass:[NSString class]]) {
UIPasteboard.generalPasteboard.string = object;
} else if([object isKindOfClass:[NSData class]]) {
[UIPasteboard.generalPasteboard setData:object forPasteboardType:@"public.data"];
} else if ([object isKindOfClass:[NSNumber class]]) {
UIPasteboard.generalPasteboard.string = [object stringValue];
} else {
// TODO: make this an alert instead of an exception
[NSException raise:NSInternalInconsistencyException
format:@"Tried to copy unsupported type: %@", [object class]];
}
[NSException raise:NSInternalInconsistencyException
format:@"Tried to copy unsupported type: %@", [object class]];
}
@end
+1 -1
View File
@@ -17,7 +17,7 @@
#define FLEX_IS_TESTING() (NSClassFromString(@"XCTest") != nil)
/// Whether we want the majority of constructors to run upon load or not.
extern BOOL FLEXConstructorsShouldRun();
extern BOOL FLEXConstructorsShouldRun(void);
/// A macro to return from the current procedure if we don't want to run constructors
#define FLEX_EXIT_IF_NO_CTORS() if (!FLEXConstructorsShouldRun()) return;
+3 -2
View File
@@ -52,7 +52,8 @@
#pragma mark - Misc Icons
@property(readonly, class) UIImage *checkerPattern;
@property(readonly, class) UIImage *hierarchyIndentPattern;
@property (readonly, class) UIImage *checkerPattern;
@property (readonly, class) UIColor *checkerPatternColor;
@property (readonly, class) UIImage *hierarchyIndentPattern;
@end
+4
View File
@@ -8838,6 +8838,10 @@ static const u_int8_t FLEXHierarchyIndentPattern3x[] = {
return FLEXImage(FLEXCheckerPattern);
}
+ (UIColor *)checkerPatternColor {
return [UIColor colorWithPatternImage:FLEXResources.checkerPattern];
}
+ (UIImage *)hierarchyIndentPattern {
return FLEXImageTemplate(FLEXHierarchyIndentPattern);
}
+9 -5
View File
@@ -135,7 +135,7 @@ BOOL FLEXConstructorsShouldRun() {
+ (UIImage *)previewImageForView:(UIView *)view {
if (CGRectIsEmpty(view.bounds)) {
return nil;
return [UIImage new];
}
CGSize viewSize = view.bounds.size;
@@ -359,14 +359,18 @@ BOOL FLEXConstructorsShouldRun() {
id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
if ([NSJSONSerialization isValidJSONObject:jsonObject]) {
prettyString = [NSString stringWithCString:[NSJSONSerialization
dataWithJSONObject:jsonObject options:NSJSONWritingPrettyPrinted error:NULL
].bytes encoding:NSUTF8StringEncoding];
// Thanks RaziPour1993
prettyString = [[NSString alloc]
initWithData:[NSJSONSerialization
dataWithJSONObject:jsonObject options:NSJSONWritingPrettyPrinted error:NULL
]
encoding:NSUTF8StringEncoding
];
// NSJSONSerialization escapes forward slashes.
// We want pretty json, so run through and unescape the slashes.
prettyString = [prettyString stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
} else {
prettyString = [NSString stringWithCString:data.bytes encoding:NSUTF8StringEncoding];
prettyString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}
return prettyString;
@@ -15,6 +15,9 @@
@property (nonatomic) UIImage *image;
@property (nonatomic) UIScrollView *scrollView;
@property (nonatomic) UIImageView *imageView;
@property (nonatomic) UITapGestureRecognizer *bgColorTapGesture;
@property (nonatomic) NSInteger backgroundColorIndex;
@property (nonatomic, readonly) NSArray<UIColor *> *backgroundColors;
@end
#pragma mark -
@@ -31,19 +34,19 @@
}
+ (instancetype)forImage:(UIImage *)image {
if (!image) {
return nil;
}
return [[self alloc] initWithImage:image];
}
- (id)initWithImage:(UIImage *)image {
NSParameterAssert(image);
self = [super init];
if (self) {
self.title = @"Preview";
self.image = image;
_backgroundColors = @[FLEXResources.checkerPatternColor, UIColor.whiteColor, UIColor.blackColor];
}
return self;
}
@@ -53,12 +56,10 @@
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithPatternImage:FLEXResources.checkerPattern];
self.imageView = [[UIImageView alloc] initWithImage:self.image];
self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
self.scrollView.delegate = self;
self.scrollView.backgroundColor = self.view.backgroundColor;
self.scrollView.backgroundColor = self.backgroundColors.firstObject;
self.scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.scrollView addSubview:self.imageView];
self.scrollView.contentSize = self.imageView.frame.size;
@@ -66,7 +67,14 @@
self.scrollView.maximumZoomScale = 2.0;
[self.view addSubview:self.scrollView];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(actionButtonPressed:)];
self.bgColorTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeBackground)];
[self.scrollView addGestureRecognizer:self.bgColorTapGesture];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:@selector(actionButtonPressed:)
];
}
- (void)viewDidLayoutSubviews {
@@ -99,6 +107,12 @@
self.scrollView.contentInset = UIEdgeInsetsMake(verticalInset, horizontalInset, verticalInset, horizontalInset);
}
- (void)changeBackground {
self.backgroundColorIndex++;
self.backgroundColorIndex %= self.backgroundColors.count;
self.scrollView.backgroundColor = self.backgroundColors[self.backgroundColorIndex];
}
- (void)actionButtonPressed:(id)sender {
static BOOL canSaveToCameraRoll = NO, didShowWarning = NO;
static dispatch_once_t onceToken;
+10 -14
View File
@@ -21,11 +21,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
UserDefaults.standard.set("foo", forKey: "FLEXamplePrefFoo")
// To show off the system log viewer, send 10 example log messages at 3 second intervals
self.repeatingLogExampleTimer = Timer(
timeInterval: 3, target: self,
selector: #selector(sendExampleLogMessage),
userInfo: nil, repeats: true
)
self.repeatingLogExampleTimer = Timer.scheduledTimer(withTimeInterval: 3, repeats: true) { [weak self] (_) in
if let self = self {
NSLog("Example log \(self.exampleLogSent)")
self.exampleLogSent += 1
if self.exampleLogSent > self.exampleLogLimit {
self.repeatingLogExampleTimer.invalidate()
}
}
}
// To show off the network logger, send several misc network requests
MiscNetworkRequests.sendExampleRequests()
@@ -56,13 +61,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let exampleLogLimit = 10
var exampleLogSent = 0
func sendExampleLogMessage() {
NSLog("Example log \(self.exampleLogSent)")
self.exampleLogSent += 1
if self.exampleLogSent > self.exampleLogLimit {
self.repeatingLogExampleTimer.invalidate()
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "FLEX"
spec.version = "4.2.1"
spec.version = "4.3.0"
spec.summary = "A set of in-app debugging and exploration tools for iOS"
spec.description = <<-DESC
- Inspect and modify views in the hierarchy.