/Neat

Syntactic sugar for class Object, especially for UIKit components

Primary LanguageSwiftMIT LicenseMIT

Neat

Swift Platforms SwiftPM

Syntactic sugar for class object, especially for UIKit UI components.

Why Use Neat?

  • Simplify Your Code: Neat helps you quickly set up class objects by removing boilerplate code.
  • Avoid Errors: Method chaining reduces the possibility of mistakes.
  • Improve Readability: Chaining properties and methods enhances code readability.

Installation

Swift Package Manager

To integrate Neat into your project using Swift Package Manager, add the following dependency to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/gnksbm/Neat.git", branch: "main")
]

Usage

Basic Usage

Initializes a UILabel with configured properties.

import Neat

let label = UILabel().nt.configure {
    $0.text("Neat")
        .font(.systemFont(ofSize: 17, weight: .semibold))
        .textColor(.black)
        .backgroundColor(.white)
}

This is equivalent to:

let label: UILabel = {
    let label = UILabel()
    label.text = "Neat"
    label.font = .systemFont(ofSize: 17, weight: .semibold)
    label.textColor = .black
    label.backgroundColor = .white
    return label
}()

Configure Nested Value

let button = UIButton().nt.configure {
    $0.configuration(.plain())
        .configuration.image(UIImage(systemName: "circle"))
        .configuration.baseForegroundColor(.secondaryLabel)
        .layer.cornerRadius(10)
        .layer.borderWidth(1)
}

Extended Commonly Used Methods

lazy var button = UIButton().nt.configure {
    $0.setTitle("Neat", for: .normal)
        .setTitleColor(.red, for: .normal)
        .setImage(UIImage(systemName: "star"), for: .normal)
        .addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
}

let tableView = UITableView().nt.configure {
    $0.register(UITableViewCell.self)
}

Non-Extended Methods Usage

let view = UIView().nt.configure {
    $0.perform {
        // Perform any direct operations on the base object. 
        $0.becomeFirstResponder()
        $0.yourMethod()
    }
}

License

Neat is licensed under the MIT License - see the LICENSE file for details.