bakkenbaeck / Sweetness

A collection of sugar and helpers for UIKit, CoreData, Foundation, Swift and more

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sweetness

Version Carthage compatible platforms License

A collection of helpers and sugar methods to sweeten your apps.

UIAlertController

Dismissable alert

let alertController = UIAlertController.dismissableAlert(title: "Not allowed access", message: "Please contact your admin to get access.")
self.presentViewController(alertController, animated: true, completion: nil)

Destructive confirmation alert

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)

Error alert

let alertController = UIAlertController.errorAlert(error)
self.presentViewController(alertController, animated: true, completion: nil)

Progress alert

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
        }
    }
}

UILabel

Calculate width

let width = self.usernameLabel.width()
// Do something with new width

UIView

Shake

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
    }
}

UIImage

Centered frame

let image = UIImage(named: "art.png")!
let frame = image.centeredFrame()
// Do something with new frame

UIViewController

Application window

let window = self.applicationWindow()

NSManagedObjectContext

Drop entity

let context = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
context.dropEntity("User")

Count entity

let context = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
let count = context.countEntity("User")

Fetch entity (with generics)

let context = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
let users: [User] = context.fetchEntity("User")

Installation

Sweetness is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Sweetness'

Sweetness is also available through Carthage. To install it, simply add the following line to your Cartfile:

github "SweetOrg/Sweetness"

License

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

Author

Bakken & Bæck AS, @SweetOrg

About

A collection of sugar and helpers for UIKit, CoreData, Foundation, Swift and more

License:Other


Languages

Language:Swift 62.3%Language:Ruby 37.7%