Skip to content

Instantly share code, notes, and snippets.

@PaulWoodIII
Last active February 6, 2022 15:01
Show Gist options
  • Save PaulWoodIII/828f982fe4ec6b0bee172f3a35a02be3 to your computer and use it in GitHub Desktop.
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
//
// 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
//
// 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
//
// 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)
}
}
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