Giter Club home page Giter Club logo

appliable's Introduction

Appliable logo

Build Code coverage Language Supported platforms

Swift Package Manager Release version License

Appliable

Appliable makes configuring objects easier and more convenient using closures.

Table of Contents
  1. Highlights
  2. Installation
  3. Examples
  4. Conformance
  5. License

Highlights

let button = UIButton().apply {
    $0.isUserInteractionEnabled = false
}
UserDefaults.standard.apply {
    $0.set("Value 1", forKey: "Key 1")
    $0.set("Value 2", forKey: "Key 2")
    $0.set("Value 3", forKey: "Key 3")
}

Installation

Requirements

  • iOS 15.0+
  • macOS 12.0+
  • watchOS 8.0+
  • tvOS 15.0+

Swift Package Manager

Appliable is available as a Swift Package.

.package(url: "https://github.com/pawello2222/Appliable.git", .upToNextMajor(from: "1.0.0"))

Examples

Classes

let button = UIButton().apply {
    $0.isUserInteractionEnabled = false
}
let label = UILabel()

label.apply {
    $0.isUserInteractionEnabled = false
}

Structs

let calendar = Calendar(identifier: .gregorian).applying {
    $0.timeZone = .init(identifier: "UTC")!
    $0.locale = .init(identifier: "en_US_POSIX")
}
var calendar = Calendar(identifier: .gregorian)

calendar.apply {
    $0.timeZone = .init(identifier: "UTC")!
    $0.locale = .init(identifier: "en_US_POSIX")
}

Block operations

UserDefaults.standard.apply {
    $0.set("Value 1", forKey: "Key 1")
    $0.set("Value 2", forKey: "Key 2")
    $0.set("Value 3", forKey: "Key 3")
}

Arrays

var array = Array(repeating: Date(), count: 3)

array.applyEach {
    $0.addTimeInterval(1000)
}
let array1 = Array(repeating: Date(), count: 3)

let array2 = array1.applyingEach {
    $0.addTimeInterval(1000)
}
let label = UILabel()
let button = UIButton()

[label, button].applyEach {
    $0.isUserInteractionEnabled = false
}

let components = [UILabel(), UIButton()].applyEach {
    $0.isUserInteractionEnabled = false
}

Conformance

Built-in conformance

  1. Value types
  • Array
  • Calendar
  • Date
  • Dictionary
  • Set
  • URL
  • URLRequest
  1. Reference types
  • JSONDecoder
  • JSONEncoder
  • PropertyListDecoder
  • PropertyListEncoder
  1. All classes inheriting from NSObject

Custom conformance

extension Calendar: Appliable {} // value types

extension JSONDecoder: ObjectAppliable {} // reference types
struct Item: Appliable {
    var value: Int?
}

let item = Item().applying {
    $0.value = 1
}

License

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.