GithubHelp home page GithubHelp logo

frandepascuali / constraintsmonitor Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 0.0 196 KB

A tool to understand constraints warnings. Nicer constraints warnings, with no setup needed.

License: MIT License

Ruby 11.67% Swift 88.33%
ios swift nslayoutconstraint autolayout warnings constraints objective-c constraints-warnings uikit

constraintsmonitor's Introduction

ConstraintsMonitor

A tool to understand constraints warnings, only adding it as a dependency.

Without ConstraintsMonitor:

[LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
	(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x600003220d20 h=--& v=--& ConstraintsMonitor_Example.MyView:0x7fcdaff03e10.height == 896   (active)>",
    "<NSLayoutConstraint:0x600003220a50 UIView:0x7fcdaff031e0.height == 200   (active)>",
    "<NSLayoutConstraint:0x600003220410 V:|-(0)-[UIView:0x7fcdaff031e0]   (active, names: '|':ConstraintsMonitor_Example.MyView:0x7fcdaff03e10 )>",
    "<NSLayoutConstraint:0x600003220aa0 V:[UIView:0x7fcdaff031e0]-(0)-[UIView:0x7fcdaff03fc0]   (active)>",
    "<NSLayoutConstraint:0x600003220b90 UIView:0x7fcdaff03fc0.bottom == ConstraintsMonitor_Example.MyView:0x7fcdaff03e10.bottom   (active)>",
    "<NSLayoutConstraint:0x600003220be0 UIView:0x7fcdaff03fc0.height == 0.2*ConstraintsMonitor_Example.MyView:0x7fcdaff03e10.height   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600003220a50 UIView:0x7fcdaff031e0.height == 200   (active)>

With ConstraintsMonitor:

[LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
	(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "UIViewControllerWrapperView.MyView.height == 896.0 (Did you set translatesAutoresizingMaskIntoConstraints = false?)",
    "MyView.UIView.height == 200.0 ",
    "MyView.UIView.top == UIViewControllerWrapperView.MyView.top (constant: 0.0)",
    "MyView.UIView.top == UIView.bottom (constant: 0.0)",
    "MyView.UIView.bottom == UIViewControllerWrapperView.MyView.bottom (constant: 0.0)",
    "MyView.UIView.height == UIViewControllerWrapperView.MyView.height (multiplier: 0.200)"
)

Will attempt to recover by breaking constraint 
MyView.UIView.height == 200.0 

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

Why?

I was tired of looking for constraints issues and realizing what was really the issue, so I created this mini tool for printing nicer constraints

Installation

pod 'ConstraintsMonitor'
dependencies: [
  .package(url: "https://github.com/FranDepascuali/ConstraintsMonitor.git", from: "1.0.1")
]

Usage

Just by including this lib in your project, you will see nicer constraints warnings

Key Features

  • Use an identifier for the constraint if supplied.
  • Use the view identifier or the class name if the view is a subclass of UIView.
  • Show the parent view, so it's easier to know where to locate the issue.

How does it work?

By overriding the description property of the NSLayoutConstraint involved, we have a nicer way of viewing constraints.

Author

You can check my blog at https://deep-thought.netlify.com/ or @FranDepascuali in twitter.

License

ConstraintsMonitor is available under the MIT license. See the LICENSE file for more info.

constraintsmonitor's People

Contributors

frandepascuali avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.