UseSweet/SweetSwift

Helpers and sugar for Swift


License
GPL-3.0+

Documentation

SweetSwift

Version Carthage compatible platforms License

Table of Contents

Enums

SweetSwift adds a count variable to your Enum so you can avoid having a special case for this.

A common scenario would be that you use enums in your UITableViewController to separate the different sections, for example:

enum SectionType: Int {
    case title, price, others, delete, count
}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return SectionType.count.rawValue
}

After adding SweetSwift you can do this instead:

import SweetSwift

enum SectionType: Int {
    case title, price, others, delete
}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return SectionType.count
}

"Hey, but this doesn't work with String types!".

Doesn't matter, you shouldn't be using that anyway since it doesn't provide you a way to return localized variations. So maybe this should be better.

enum Section: Int {
    case title, price, others, delete

    func toString() -> String? {
        switch self {
        case .title:
            return NSLocalizedString("Title", comment: "")
        case .price:
            return NSLocalizedString("Price", comment: "")
        case .others:
            return NSLocalizedString("Others", comment: "")
        case .delete:
            return nil
        }
    }
}

Strings

SweetSwift adds a convenience property to access the length of a String.

You'll be able to replace:

"hello world".characters.count

With this:

"hello world".length

Installation

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

pod 'SweetSwift' , '~> 1'

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

github "bakkenbaeck/SweetSwift"

License

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

Author

Bakken & Bæck, @bakkenbaeck