All Projects β†’ marty-suzuki β†’ Ducttape

marty-suzuki / Ducttape

Licence: mit
πŸ“¦ KeyPath dynamicMemberLookup based syntax sugar for Swift.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Ducttape

Functionkit
A framework for functional types and operations designed to fit naturally into Swift.
Stars: ✭ 302 (+118.84%)
Mutual labels:  tvos, watchos, cocoapods, carthage, swift-package-manager
Swifterswift
A handy collection of more than 500 native Swift extensions to boost your productivity.
Stars: ✭ 10,706 (+7657.97%)
Mutual labels:  tvos, watchos, cocoapods, carthage, swift-package-manager
Web3.swift
A pure swift Ethereum Web3 library
Stars: ✭ 295 (+113.77%)
Mutual labels:  tvos, watchos, cocoapods, carthage, swift-package-manager
Swiftframeworktemplate
A template for new Swift iOS / macOS / tvOS / watchOS Framework project ready with travis-ci, cocoapods, Carthage, SwiftPM and a Readme file
Stars: ✭ 527 (+281.88%)
Mutual labels:  tvos, watchos, cocoapods, carthage, swift-package-manager
Guitar
A Cross-Platform String and Regular Expression Library written in Swift.
Stars: ✭ 641 (+364.49%)
Mutual labels:  tvos, watchos, cocoapods, carthage, swift-package-manager
L10n Swift
Localization of the application with ability to change language "on the fly" and support for plural form in any language.
Stars: ✭ 177 (+28.26%)
Mutual labels:  tvos, watchos, cocoapods, carthage, swift-package-manager
Cdmarkdownkit
An extensive Swift framework providing simple and customizable markdown parsing.
Stars: ✭ 158 (+14.49%)
Mutual labels:  tvos, watchos, cocoapods, carthage, swift-package-manager
Swiftlinkpreview
It makes a preview from an URL, grabbing all the information such as title, relevant texts and images.
Stars: ✭ 1,216 (+781.16%)
Mutual labels:  tvos, watchos, cocoapods, carthage, swift-package-manager
Contentful.swift
A delightful Swift interface to Contentful's content delivery API.
Stars: ✭ 132 (-4.35%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Swiftyattributes
A Swifty API for attributed strings
Stars: ✭ 1,303 (+844.2%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Sqift
Powerful Swift wrapper for SQLite
Stars: ✭ 119 (-13.77%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Datez
πŸ“† Breeze through Date, DateComponents, and TimeInterval with Swift!
Stars: ✭ 254 (+84.06%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Xcglogger
A debug log framework for use in Swift projects. Allows you to log details to the console (and optionally a file), just like you would have with NSLog() or print(), but with additional information, such as the date, function name, filename and line number.
Stars: ✭ 3,710 (+2588.41%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Coregpx
A library for parsing and creation of GPX location files. Purely Swift.
Stars: ✭ 132 (-4.35%)
Mutual labels:  watchos, cocoapods, carthage, swift-package-manager
Sdwebimagewebpcoder
A WebP coder plugin for SDWebImage, use libwebp
Stars: ✭ 101 (-26.81%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Skeletonui
☠️ Elegant skeleton loading animation in SwiftUI and Combine
Stars: ✭ 275 (+99.28%)
Mutual labels:  tvos, watchos, cocoapods, swift-package-manager
Randomkit
Random data generation in Swift
Stars: ✭ 1,458 (+956.52%)
Mutual labels:  watchos, cocoapods, carthage, swift-package-manager
Queuer
Queuer is a queue manager, built on top of OperationQueue and Dispatch (aka GCD).
Stars: ✭ 964 (+598.55%)
Mutual labels:  tvos, watchos, carthage, swift-package-manager
Dots
Lightweight Concurrent Networking Framework
Stars: ✭ 35 (-74.64%)
Mutual labels:  tvos, watchos, carthage, swift-package-manager
Mechanica
A cross-platform library of Swift utils to ease your iOS | macOS | watchOS | tvOS and Linux development.
Stars: ✭ 27 (-80.43%)
Mutual labels:  tvos, watchos, carthage, swift-package-manager

DuctTape

CI Status Pod CarthageSwiftPM
Swift5 Platform License

πŸ“¦ KeyPath dynamicMemberLookup based syntax sugar for Swift.

let label = UILabel().ductTape
    .numberOfLines(0)
    .textColor(.red)
    .text("Hello, World!!")
    .build()

Above is same as below definition.

let label: UILabel = {
    let label = UILabel()
    label.numberOfLines = 0
    label.textColor = .red
    label.text = "Hello, World!!"
    return label
}()

Usage

NSObject already has been compatible with DuctTape, so you can access .ductTape property like below.

let builder: Builder<UIView> = UIView().ductTape

If you access .ductTape, it returns Builder that provides setter of properties via KeyPath dynamicMemberLookup.

let view: UIView = UIView().ductTape
    .backgroundColor(.red)
    .translatesAutoresizingMaskIntoConstraints(false)
    .build()

Finally, if you call .build(), Builder returns instance that has set property values.

How to access methods

If you want to access methods of object which is building, func reinforce(_ handler: (Base) -> Void) Builder<Base> enable to access methods.

let collectionView = UICollectionView().ductTape
    .backgroundColor(.red)
    .reinforce { collectionView in
        collectionView.register(UITableViewCell.self, forCellWithReuseIdentifier: "Cell")
    }
    .build()

Builder has func reinforce<T1, ...>(_ t1: T1, ..., handler: (Base) -> Void) Builder<Base> methods. In additional usage, be able to access outside object with func reinforce if passing objects as arguments.

lazy var collectionView = UICollectionView().ductTape
    .translatesAutoresizingMaskIntoConstraints(false)
    .reinforce(view) { collectionView, view in
        view.addSubview(collectionView)
        NSLayoutConstraint.activate([
            view.topAnchor.constraint(equalTo: collectionView.topAnchor),
            view.leadingAnchor.constraint(equalTo: collectionView.leadingAnchor),
            view.trailingAnchor.constraint(equalTo: collectionView.trailingAnchor),
            view.bottomAnchor.constraint(equalTo: collectionView.bottomAnchor)
        ])
    }
    .build()

How to use DuctTape with self-implemented classes

There are two ways to use DuctTape.

  1. Use DuctTapeCompatible
class Dog: DuctTapeCompatible {
    var name: String
}

let dog = Dog().ductTape
    .name("Copernicus")
    .build()
  1. Use Builder directly
class Dog {
    var name: String
}

let dog = Builder(Dog())
    .name("Copernicus")
    .build()

Sample Code

class ViewController: UIViewController {

    let flowLayout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
        .ductTape
        .minimumLineSpacing(10)
        .minimumInteritemSpacing(10)
        .itemSize(CGSize(width: 100, height: 100))
        .scrollDirection(.vertical)
        .build()

    lazy var collectionView: UICollectionView = UICollectionView(frame: .zero,
                                                                 collectionViewLayout: flowLayout)
        .ductTape
        .dataSource(self)
        .delegate(self)
        .translatesAutoresizingMaskIntoConstraints(false)
        .reinforce {
            $0.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
        }
        .build()

    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(collectionView)
        NSLayoutConstraint.activate([
            view.topAnchor.constraint(equalTo: collectionView.topAnchor),
            view.leadingAnchor.constraint(equalTo: collectionView.leadingAnchor),
            view.trailingAnchor.constraint(equalTo: collectionView.trailingAnchor),
            view.bottomAnchor.constraint(equalTo: collectionView.bottomAnchor)
        ])
    }
}

Requirement

  • Xcode 11
  • macOS 10.10
  • iOS 9.0
  • tvOS 10.0
  • watchOS 3.0

Installation

CocoaPods

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

pod "DuctTape"

Carthage

If you’re using Carthage, simply add DuctTape to your Cartfile:

github "marty-suzuki/DuctTape"

Swift Package Manager

Simply add the following line to your Package.swift:

.package(url: "https://github.com/marty-suzuki/DuctTape.git", from: "version")

License

DuctTape is released under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].