Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you label views in AutoLayout console output without using Storyboards?

I'm watching through the WWDC talks on AutoLayout, and I've learned that having StoryboardID set on your views makes the console output for constraint conflicts much easier to read (i.e. you get a name instead of just an address). They show you where to set the StoryboardID (formerly just "Identifier") in Interface Builder, but is there a way to do it in code? I'm trying to debug a large and complicated set of views that I didn't write myself, in an app that's 100% programmatic, that has many unsatisfiable constraints, and that was (somehow) working in iOS 7 but started breaking in iOS 8. I would love to get a clear picture of which <UIView:0x8675309> is actually causing the problem.

I looked over the UIView class reference, no "Identifier" or "StoryboardID" to be found.

Wouldn't be too surprised if the answer is "nope". After all it's called a Storyboard ID for a reason. But I would appreciate a confirmation, and a workaround to make the AutoLayout console dump more readable if possible.

like image 744
Garrett Disco Avatar asked Jan 28 '15 22:01

Garrett Disco


1 Answers

I'm a little late to the party, but I hope this helps. There is indeed an extremely simple attribute on UIView, through it's conformance to UIAccessibilityIdentification:

centerView.accessibilityIdentifier = "Center Foobar View"
containerView.accessibilityIdentifier = "Container BingBat View"

This yields debugger output like you'd expect:

"<NSLayoutConstraint:0x7fe3fa3ade50 Center Foobar View.centerX == Container BingBat View.centerX (Names: Center Foobar View:0x7fe3fa3a1700, Container BingBat View:0x7fe3fa3856c0 )>",

like image 128
Chris Trahey Avatar answered Nov 15 '22 23:11

Chris Trahey