Latest 1.1.1
Homepage https://github.com/bakkenbaeck/SweetSwift
License MIT
Platforms ios 8.0, osx 10.9, watchos 2.0, tvos 9.0, requires ARC
Authors

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

Latest podspec

{
    "name": "SweetSwift",
    "summary": "Helpers and sugar for Swift.",
    "version": "1.1.1",
    "homepage": "https://github.com/bakkenbaeck/SweetSwift",
    "license": "MIT",
    "authors": {
        "Bakken & Bu00e6ck": "[email protected]"
    },
    "source": {
        "git": "https://github.com/bakkenbaeck/SweetSwift.git",
        "tag": "1.1.1"
    },
    "social_media_url": "https://twitter.com/bakkenbaeck",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "requires_arc": true,
    "source_files": "Sources/**/*"
}

Pin It on Pinterest

Share This