Last active
February 6, 2022 15:01
-
-
Save PaulWoodIII/828f982fe4ec6b0bee172f3a35a02be3 to your computer and use it in GitHub Desktop.
Provide Swift with the amazing ability to visually print a UICollectionView's VisualRecursiveDescription
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIView+VisualRecursiveDescription.h | |
// | |
// Created by Paul Wood on 8/28/19. | |
// Copyright © 2019 Paul Wood. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import <UIKit/UIKit.h> | |
NS_ASSUME_NONNULL_BEGIN | |
@interface UIView (VisualRecursiveDescription) | |
+ (NSString * _Nullable)visualRecursiveDescription:(UIView *)collectionView; | |
@end | |
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIView+VisualRecursiveDescription.m | |
// | |
// Created by Paul Wood on 8/28/19. | |
// Copyright © 2019 Paul Wood. All rights reserved. | |
// | |
#import "UIView+VisualRecursiveDescription.h" | |
@import UIKit; | |
@implementation UIView (VisualRecursiveDescription) | |
+ (NSString * _Nullable)visualRecursiveDescription:(UIView *)view { | |
#ifdef DEBUG | |
SEL selector = NSSelectorFromString(@"_visualRecursiveDescription"); | |
if ([view canPerformAction:selector withSender:nil]) { | |
IMP imp = [view methodForSelector:selector]; | |
NSString* (*func)(id, SEL) = (void *)imp; | |
NSString *visualDebugDescription = func(view, selector); | |
return visualDebugDescription; | |
} | |
#endif | |
return nil; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIView+VisualRecursiveDescription.swift | |
// | |
// Created by Paul Wood on 8/29/19. | |
// Copyright © 2019 Paul Wood. All rights reserved. | |
// | |
import Foundation | |
extension UIView { | |
var visualRecursiveDescription: String? { | |
return UIView.visualRecursiveDescription(self) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | |
#if DEBUG | |
print(collectionView.visualRecursiveDescription ?? "Description Not Available") | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment