How could Xcode improve for auto layout handling ?

I have mixed feelings about SwiftUI. It seems fun for sure, really powerful, but…

A major issue is that it seems we give up graphical design to return to declarative code. Just as if Finder returned to command line editor…

That seems also to blur the concepts of MVC.

Most of my concerns are reflected here:

h ttps://medium.com/better-programming/swiftui-vs-autolayout-pros-and-cons-of-both-approaches-c09b37b9aff2


On the other hand, Autolayout may be really hard to use or debug sometimes, lacks some capabilities, makes it easy to get lost when we have to browse tons of constraints one by one to find out what’s going wrong.


Hence I would like to share some ideas here: how could AutoLayout improve, maybe catching some ideas from SwiftUI.


1. Be able to edit auto layout constraints in code


Main goal would be to be able to understand and check all the constraints that apply to an IBOutlet in a single place, departing from present situation where you have to inspect one by one, using Size Inspector.


Today, we can attach an IBOutlet to a constraint. And I often do this when I need to fine tune the constraint.

But is is really tedious and not easy to keep the mental links between IBOutlets and those constraints

Today, I write things like:


    @IBOutlet weak var zoomInButton: UIButton!

    @IBOutlet weak var buttonInViewToImageTopConstraint: NSLayoutConstraint!
    @IBOutlet weak var buttonInViewCenterXConstraint: NSLayoutConstraint!

And have the constraints change scattered in code.


So first idea.

When declaring an IBOutlet, be able to get the list of constraints declared in IB.

The mechanism could be similar to IBInspectable, but 2 ways: change in IB should reflect in code.

    @IBOutlet weak var zoomInButton: UIButton! {
            // all the constraints that are defined in IB
      // Identifier of constraint to search when message in log
      // including all variations
    }


A complexity is that same constraint may be expressed in different objects: (eg, distance between 2): need to keep them sync’ed.

Need also to decide who is source of truth.


2. New constraint semantic, such as constant computed from other var ; should it introduce didConstraint, willConstraint, to tell when it should be called ?

    @IBOutlet weak var zoomInButton: UIButton! {
        didConstraint {
      // new constraints, maybe with reacher semantic
       }
    }


3. Computation as in computed var, for runtime ; such as like conditional constraint, object aspect, …

    @IBOutlet weak var zoomInButton: UIButton! {
        didConstraint {
          // new constraints, maybe with reacher semantic, like conditional constraint
    }


I did not look at how this would be feasible, what to handle what is static vs runtime property…

So, some ideas may be weird.

Accepted Reply

Closing the thread.

Replies

Closing the thread.