Latest 2.3.1
Homepage https://github.com/pedrommcarrasco/Sucrose
License MIT
Platforms ios 9.0

Sucrose

Sucrose (/suː.krəʊz/), noun

"the type of sugar that exists naturally in most plants that grow on land"

🍬 My everyday sugar. Feel free to use it as a framework or simply add a specific file to your project.

CocoaPods

Content

Extensions

Collection

let array = ["A", "B", "C"]
let item = array[4] // will crash
let item = array[safe: 4] // won't crash & returns nil

NSObject

// Similar to `then` by @devxoul
let view: UIView = .create {
    $0.background = .red
    $0.isHidden = true
}

Optional

var string: String? 
var isValid: Bool

string = nil
isValid = string.isNilOrEmpty // true

string = ""
isValid = string.isNilOrEmpty // true

string = "ABC"
isValid = string.isNilOrEmpty // false

UIButton

let UIButton(image: UIImage(named: "test")) // Sets the image of the UIButton's imageView

UIStackView

// Add multiple views to a UIStackView's arragedSubviews. 
// Supports variadic parameters or an array of UIView
stackView.addArrangedSubviews(viewA, viewB, viewC)
stackView.addArrangedSubviews([viewA, viewB, viewC])

UIView

// Add multiple views to a UIView's subviews. 
// Supports variadic parameters or an array of UIView
view.addSubviews(viewA, viewB, viewC)
view.addSubviews([viewA, viewB, viewC])

// Optimize (inspired by @hyperoslo)
view.optimize // Sets clipsToBounds and isOpaque to true

// Get the view name to register as an identifier or debug
print(CellExample.name) // String(describing:)
register(CellExample.self, forCellWithReuseIdentifier: CellExample.name)

// Circular View
viewA.asCircle()

UITableView

// Register Cell
tableView.register(ExampleCell.self)

// Dequeue Cell
let exampleCell = tableView.dequeueCell(for: indexPath, as: ExampleCell.self)

UICollectionView

// Register Cell
collectionView(ExampleCell.self)

// Dequeue Cell
let exampleCell = collectionView(for: indexPath, as: ExampleCell.self)

UIViewController

// Add multiple UIViewControllers as children of another. 
// Supports variadic parameters or an array of UIViewController
viewController.addChilds(headerViewController, listViewController)
viewController.addChilds([headerViewController, listViewController])

// Remove an UIViewController from its parent
headerViewController.remove()

Instalation 📦

Sucrose is available through CocoaPods. To do so, add the following line to your Podfile:

pod 'Sucrose'

And then run the following command in terminal:

pod install

Latest podspec

{
    "name": "Sucrose",
    "swift_version": "4.2",
    "version": "2.3.1",
    "summary": "ud83cudf6c Everyday sugar",
    "description": "Collection of handy methods & objects",
    "homepage": "https://github.com/pedrommcarrasco/Sucrose",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": "Pedro Carrasco",
    "social_media_url": "http://twitter.com/pedrommcarrasco",
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/pedrommcarrasco/Sucrose.git",
        "tag": "2.3.1"
    },
    "source_files": "Sucrose/**/*",
    "exclude_files": "Sucrose/*.plist"
}

Pin It on Pinterest

Share This