Here is a handy trick you can do to aid in your AutoLayout debugging. You can add your own name
property to UIView
via a category, and overload its description
method to include your new name
. This doesn't quite give you a visible name in the AutoLayout debug info, but lets you easily po
a view from its address and see its given name.
Then just assign the applicable names in your view controller:
- (void)viewDidLoad {
[super viewDidLoad];
self.firstView.name = @"MyViewController.firstView";
self.secondView.name = @"MyViewController.secondView";
}
Now when you see something like this:
<NSAutoresizingMaskLayoutConstraint:0x175086220 h=-&- v=-&- UIView:0x147533250.height == UIView:0x14760b4a0.height>
You can just po
the view addresses:
po 0x147533250
MyViewController.firstView <UIView: 0x147533250>
po 0x14760b4a0
MyViewController.secondView <UIView: 0x14760b4a0>
Here's the category code:
UIView+Name.h
#import <UIKit/UIKit.h>
@interface UIView (Name)
@property (strong, nonatomic) NSString *name;
- (NSString *)description;
@end
UIView+Name.m
#import "UIView+Name.h"
#import <objc/runtime.h>
@implementation UIView (Name)
- (NSString *)name {
return objc_getAssociatedObject(self, @selector(name));
}
- (void)setName:(NSString *)name {
objc_setAssociatedObject(self, @selector(name), name, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (NSString *)description {
return [NSString stringWithFormat:@"%@ %@", self.name, [super description]];
}
@end