// Before
let cell = tableView.dequeueReusableCell(withIdentifier: "TitleCell", for: indexPath) as! TitleCell
// After
let cell = tableView.dequeue(TitleCell.self, for: indexPath)
// Before
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell", for: indexPath) as! CollectionViewCell
// After
let cell = collectionView.dequeue(CollectionViewCell.self, for: indexPath)
Simple protocol extensions to simplify registering a cell in UITableViewController and UICollectionViewController.
Before:
self.tableView.registerClass(ItemCell.self, forCellReuseIdentifier: "ItemCell")
After:
self.tableView.register(ItemCell.self)
Also, accessing the cell identifier is as easy as using ItemCell.reuseIdentifier
.
let alertController = UIAlertController.dismissableAlert(title: "Not allowed access", message: "Please contact your admin to get access.")
self.presentViewController(alertController, animated: true, completion: nil)
let alertController = UIAlertController.destructiveConfirmationAlert(message: "Are you sure you want to log out?", destructiveActionTitle: "Log out") {
self.controllerDelegate?.settingsControllerDidPressLogoutButton(self)
}
self.presentViewController(alertController, animated: true, completion: nil)
let alertController = UIAlertController.errorAlert(error)
self.presentViewController(alertController, animated: true, completion: nil)
let progressAlert = UIAlertController.progressAlert("Creating album...")
self.presentViewController(progressAlert, animated: true, completion: nil)
self.fetcher.createAlbum(title: self.titleTextField.text, photos: self.selectedPhotos) { error in
progressAlert.dismissViewControllerAnimated(true) {
if let error = error {
let alertController = UIAlertController.errorAlert(error)
self.presentViewController(alertController, animated: true, completion: nil)
} else {
// Success
}
}
}
let width = self.usernameLabel.width()
// Do something with new width
self.fetcher.authenticate(username, password: password) { clientID, clientSecret, accessToken, refreshToken, expiresIn, error in
if let error = error {
// Update UI to display error
self.tableView.shake()
} else {
// success
}
}
let image = UIImage(named: "art.png")!
let frame = image.centeredFrame()
// Do something with new frame
let image = UIImage(color: .red)
button.setBackgroundImage(image, for: .normal)
or, if you need the image to have specific dimensions
let image = UIImage(color: .red, size: someSize)
let window = self.applicationWindow()
SweetUIKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SweetUIKit'
SweetUIKit is also available through Carthage. To install it, simply add the following line to your Cartfile:
github "UseSweet/SweetUIKit" ~> 1.0
SweetUIKit is available under the MIT license. See the LICENSE file for more info.
Bakken & Bæck, @use_sweet