SweetUI adds a little sugar to UIKit. Goals:
View
and ViewController
classes you'll be saved from dealing with init(coder:)
and init(nibName:bundle:)
.HStack
) and modifiers that allow standard UIKit view layouts to be expressed declaratively. In most cases you'll never need to directly deal with NSLayoutConstraint
s.Cancellable
s reducing boiler plate code even further.async
/await
UIViewController
properties (e.g. title
, toolbar
, navigationItem
, tabBarItem
) with CombineFlowController
for managing a sequence of view controllersUICollectionViewCompositionalLayout
and UICollectionViewCompositionalLayout.list
LayoutView
for creating reusable layout templatesThe follow code shows a simple ViewController
subclass. Note:
init
(neither init(nibName:bundle:)
or init(coder:)
are required)import UIKit
import SweetUI
final class SimpleExampleViewController: ViewController {
@Published var name: String
lazy var rootView = ZStack(alignment: .center) {
VStack(alignment: .center) {
UILabel()
.font(.largeTitle)
.text("Hello \(name)!")
UILabel()
.font(.subheadline)
.text("Welcome to SweetUI")
}
}
init(name: String) {
self.name = name
super.init()
}
}
The Demo app contains more examples of what's possible with SweetUI.
scene(_ scene:willConnectTo:options:)
with: func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let scene = scene as? UIWindowScene else {
preconditionFailure("Unexpected scene type \(Self.self) can only connect to a UIWindowScene.")
}
let window = UIWindow(windowScene: scene)
self.window = window
window.windowScene = scene
window.rootViewController = RootViewController() // where RootViewController is the app's initial viewController.
window.makeKeyAndVisible()
}
ViewBodyProvider
to an existing viewThe reccommend way to use declarative view layout is to subclass one of the provided abstract classes: View
, Control
, CollectionViewCell
and CollectionReusableView
.
If it is not possible to subclass from one of these classes then there are two alternatives approaches:
ViewBodyProvider
. ViewBodyProvider
requires the conforming class to be final
and initializeBody()
to be called at the end of the designated init
, E.G.:final class CustomControl: UIControl, ViewBodyProvider {
let body = UILabel()
.text("Hiya!")
init() {
super.init(frame: .zero)
initializeBodyHosting()
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Circular reference
errorlink |
Stars: 5 |
Last commit: 25 minutes ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics