Swiftpack.co - sobabear/AddThen as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by sobabear.
sobabear/AddThen 1.2.3
🎨 Adding view sugar for UIKit with SwiftUI style
⭐️ 12
🕓 4 weeks ago
iOS
.package(url: "https://github.com/sobabear/AddThen.git", from: "1.2.3")

AddThen

CI Status Version License Platform

🎨 View instance sugar for Swift & UIKit

Example

Add UIView & UIViewController code with AddThen


let label = UILabel()
label.backgroundColor = .red
label.text = "Hello, World"

...

view.addSubview(label)

This is equivalent to :

let label = UILabel()

...

view.add(label) {
  $0.backgroundColor = .red
  $0.text = "Hello, World!"
}

view.add(
  UIStackView { 
    UIButton()
    UIView()
    UIImageView()
  }
)

Also very useful with SnapKit

let label = UILabel()

...

view.add(label) {
  $0.backgroundColor = .red
  $0.text = "Hello, World!"
  
  $0.snp.makeConstraints {
    $0.edges.equalToSuperview()
  }
}

More SwiftUIfully

/// in certain function in UIViewController
let label = UILabel()

body {
    label.then({ $0.textColor = .red })
    UIButton()

}

body {
    if true {
        UIView()
    } else {
        EmptyView() // EmptyView will not be added 
    }
}

if you want to handle certain view which should not be added, use Emptiable or EmptyView

Requirements

  • iOS 9.0+ (11.0+ recommended)
  • Xcode 12.0+
  • Swfit 5.0

Installation

AddThen is available through CocoaPods & SPM. To install it, simply add the following line to your Podfile:

cocoapod

pod 'AddThen'

Swift Package Manager

import PackageDescription

let package = Package(
  name: "MyApp",
  dependencies: [
    .package(url: "https://github.com/sobabear/AddThen", .upToNextMajor(from: "1.2.3")),
  ]
)

Author

  • Yongjun Lee, stareta1202
  • Chanwoo Cho, GREENOVER

License

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

GitHub

link
Stars: 12
Last commit: 4 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Fix Typo
4 weeks ago

nit

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics