Giter Club home page Giter Club logo

swifthelpset's Introduction

SwiftHelpSet

BuddyBuild

Set of Swift utilities for your iOS apps

Installation

pod 'SwiftHelpSet', '~> 1.0'

Networking

The networking layer is built over two different objects: the APIModule conforming object and the Resource. Conform to the APIModule protocol like below:

final class UserModule: APIModule {
    let baseAPIURL: String = "http://myserver.ext/api/user"

    func load<Object>(resource: Resource<Object>, completion: Completion<Object, NSError> -> ()) -> NSURLSession {

        // do the request, calling an API middleware
        // return the request
    }
}

Then, create your own resource

final class User {
    let id: String

    init(id: String) {
        self.id = id
    }
}

extension User {
    static var All: Resource<[User]> {
        return Resource(
            endpoint: Endpoint(
                path: "/",
                method: .GET,
                parameters: nil,
                headers: nil
            ),
            parseJSON: { json -> [User] in
                // parse the JSON
                // return the array of User
            }
        )
    }
}

Then call your APIModule as below

UserModule().load(User.All) { result in
    // switch over the Completion enum
}

Thanks to @ChrisEidhof for the Resource idea.

Bind

The help set allows you to create a more functional project by using the Bindable type. Declare your public variable as

var currentUser = Bindable<User>(user)

Then, from your class, you can listen changes to the variable currentUser by doing

objectReference.currentUser.bind = { user in
    // Do something when the currentUser changes
}

Foundation wrappers

Use Permission and Purchase to avoid the use of delegates for purchasing and for asking permissions. Use closures instead.

Use NotificationCenter to get a more powerful and smart wrapper around NSNotificationCenter

Foundation extensions

Array

Use the method get(at index: Int) -> Element? on the array to secure get the element at index. Added also the method remove<T: Equatable>(object: T) -> Int? that removes an equatable object from the array and returns the position if it was found

String

New properties to get simply more info about the string: isEmail, isPhoneNumber, isBlank, lenght and even localized that returns the localized string for the key

Int

Easily check if an Int value is in a range by using isInRange(range: Range<Int>) -> Bool method.

Dictionary

Mix two dictionaries together by calling the += operator

NSDate

No more .OrderedAscending or .OrderedSame to compare two NSDate instances. You can use the operators >, <, =

UIKit Wrappers

Use the SwiftyTableView, SwiftyScrollView and the SwiftyTextField to avoid the use of delegates as below

let tableView = SwiftyTableView()

tableView.configureNumberOfSections = { return 1 }

tableView.numberOfRowsPerSection = { section in
    return 2
}

tableView.cellForIndexPath = { indexPath, tableView in
    return UITableViewCell()
}

CABasicAnimation wrapper

Create your own animation easily. The wrapper allows you to create simple rotation animations only, but you can easily extend it.

let animation = BasicAnimation.rotationAnimation(on: .z, duration: 1)

animation.onStart = { animation in
    // do something at the start of the animation
}

animation.onStop = { animation, finished in
    // do something at the end
    animation.remove()
}

animation.add(to: layer)

Generic Table View Controller

Create your own table view controller easily, just passing a valid set of data

let genericTable = SwiftyGenericTableViewController<MyTableViewCell, User>()

genericTable.cellForModel = { cell, model in
    // setup the cell
    return cell
}

genericTable.onSelection = { indexPath, model in
    // push or do something
}

genericTable.dataSource = userArray

UIControl Extension

Define your action on UIControl trigger without using the ugly syntax addTarget(...).

let button = UIButton(frame: .zero).bind(.TouchUpInside) { button in
    // Do something
}

swifthelpset's People

Contributors

dalu93 avatar

Watchers

Carabineiro avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.