Hello, SwiftUI! Goodbye, SwiftUI!

Hello, SwiftUI!

What fascinates you will lead you to grow.

At WWDC2019, swiftUI was born as a magic ring.

  • Declarative grammar: Write pages as if they were poetry;
  • What YOU see is what you get: to create as freely as a painter;
  • No constraints: No longer like a nanny to carefully set the constraints of each view, no constraints, good mood fly;
  • Less code: Not more code, but less code;
  • Chain syntax: click and you have everything you want.
  • Building blocks: Like a child building blocks, pages are built block by block.
  • Apple system full platform support: Learn SwiftUI, iOS, iPadOS, MacOS, WatchOS, TVOS five systems are in your bag;

The more I said, the more excited I felt that SwiftUI had been mesmerized by this “Ring”. Let’s say “Hello, SwiftUI!” .

Goodbye, SwiftUI!

“After the tide goes out, I know who is swimming naked”, so “after the excitement, I know how strong loneliness is”.

All you need to do is say “SwiftUI” on iOS 13+, and it will put you in the doghouse!

“Why do we support iOS9 when it’s six years old?” I challenged my boss with a strong voice.

The boss took a whiff of his Cuban cigar, exhaled it, and said, “Old users are users, and every user has a value. The world of business is more than technology!” The boss touched my head, then turned and walked away, leaving a dark shadow for me to savour alone!

So, let’s say “Goodbye, SwiftUI!”

Hello, StackUI

StackUI making address

Wait, guys. It’s still going on. There’s no ending. Welcome to StackUI, which borrows some of SwiftUI’s features:

  • Declarative syntax like SwiftUI;
  • Data driven UI, update data UI automatically update;
  • Chained syntax configuration UIKit;

Sample images and code are as follows:

/ / define
@Live var nickName: String? = "User name"
@Live var desc: String? = "Users are lazy and leave nothing!"

/ / use
HStack(distribution: .equalCentering, alignment: .center) {
    HStack(alignment: .center, spacing: 5) {
        ImageView().image(UIImage(named: "avatar")).size(width: 40, height: 40)
        VStack {
            Label($nickName).font(.systemFont(ofSize: 18, weight: .medium))
            Label().text($desc).font(.systemFont(ofSize: 12)).textColor(.gray)
        }
    }
    ImageView().image(UIImage(named: "arrow_right"))}/ / update
nickName = "Jay Chou"
desc = "Ouch, not bad ❤️"
Copy the code

Please note that StackUI is available on iOS 9+ at 🎉🎉🎉, which allows you to experience SwiftUI earlier so that it will be easier to learn SwiftUI later.

StackUI VS SwiftUI

StackUI = UIStackView+ SwiftUI some new features

StackUI is a Swiftui-like UI framework built on top of UIStackView after incorporating some of the new SwiftUI features. In order to use StackUI, you need to understand UIStackView first, for example, uistackView. Distribution and uistackView. Alignment.

StackUI uses @propertyWrapper, @ResultBuilder, chain syntax and other features that will help you learn SwiftUI in the future.

Why use itStackUI

  • StackUIOn the body ofSwiftUIA number of features to simplify UI development. Do the same thing with less code. (At least greatly reduce the amount of tedious constraint code written)
  • Declarative syntax is already the trend of the future, Flutter, SwiftUI, etc. There will be more similar technologies in the future.StackUIDeclarative syntax is still rudimentary, but it allows you to touch the future.
  • WWDC has new technologies coming out every year, but actual projects don’t get to use them first. If you can take the features of the new technology and then translate them into the technology that the older version of the system can use. Not only do not delay the learning of new technology, but also meet the requirements of the actual project, the best of both worlds. Knowing StackUI also helps you think about how to apply new technologies to old projects.

StackUIMore features

  • ForEach,IfStatement support;
  • supportHScrollStack.VScrollStackWhen the content exceeds the width or height of the Stack, automatically start scrolling;
  • RxSwifttheDriveruse
  • Flexible extension of custom class supportStackUI;

For more details, click the StackUI Github address.

StackUIMatters needing attention

SwiftUI configures the view. Only the view data model is configured and converted to the real view control when the view is finally displayed. So, SwiftUI views are very lightweight.

StackUI views, however, are real view controls, and each nested layer creates another layer of view. This is one of the biggest differences between StackUI and SwiftUI.

Therefore, use caution when laying out complex views in the cells of the list.

StackUI making address

Click the StackUI Github address for more details!