Sucrose (/suː.krəʊz/), noun
"the type of sugar that exists naturally in most plants that grow on land"
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()
UIEdgeInsets
// Convinient initializers
let insetsA = UIEdgeInsets(vertical: 10) // ((top: 10, left: 0, bottom: 10, right: 0)
let insetsA = UIEdgeInsets(right: 10) // ((top: 0, left: 0, bottom: 0, right: 10)
📦
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