Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.