GoodSwift 0.7.0

GoodSwift 0.7.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Aug 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Marek Spalek.


Downloads

Total660
Week55
Month159

Installs

Apps27
Apps WeekApps This Week 5
Test Targets6
Test WeekTests This week 2
powered by Segment

GitHub

Stars4
Watchers3
Forks3
Issues1
Contributors4
Pull Requests1

Code

Files3
LOCLines of Code 333


 
Depends on:
Alamofire~> 4.5
Unbox~> 2.5
 

GoodSwift 0.7.0

.goodswift

Some good swift extensions, handfully crafted by GoodRequest team.

Requirements

  • iOS 9.0+
  • Xcode 8.2+
  • Swift 3.0+

Installation

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

pod 'GoodSwift'

Usage

Mapping

.goodswift allows you to easily decode JSON objects from Alamofire responses using Unbox decoder. You can see examples how to map your model in Unbox readme.

import Unbox

struct Foo {
    let origin: String
    let url:    URL
}

extension Foo: Unboxable {
    init(unboxer: Unboxer) throws {
        self.origin = try unboxer.unbox(key: "origin")
        self.url = try unboxer.unbox(key: "url")
    }
}

Then you just need to use unbox or unboxArray functions to decode your model.

import Alamofire
import GoodSwift

Alamofire.request("https://httpbin.org/get").unbox(completion: { (response: DataResponse<Foo>) in
    switch response.result {
    case .success(let foo):
        // Decoded object
    case .failure(let error):
        // Handle error
    }
})

Logging

Automatic logging is enabled when there is Active Compilation Conditions flag DEBUG defined in project’s Build Settings. If you have added .goodswift using CocoaPods you need to add flag DEBUG manually into Active Compilation Conditions in .goodswift pod Build Settings. If you don’t want to add this flag manually after each pod install you just need to add this script at the end of your Podfile.

post_install do |installer|
    installer.pods_project.targets.each do |target|
        if target.name == 'GoodSwift'
            target.build_configurations.each do |config|
                if config.name == 'Debug'
                    config.build_settings['SWIFT_ACTIVE_COMPILATION_CONDITIONS'] = 'DEBUG'
                    else
                    config.build_settings['SWIFT_ACTIVE_COMPILATION_CONDITIONS'] = ''
                end
            end
        end
    end
end

Log level

You can choose logging level by setting logLevel static variable from DataRequest class. For now you can choose from these logging levels:

  • error - prints only when error occurs
  • info (default) - prints request url with response status and error when occurs
  • verbose - prints everything including request body and response object

Chain animations

AnimationChain allows you to easily chain UIView animations:

UIView.animationChain.animate(withDuration: 2) {
    view.alpha = 0.0
}.animate(withDuration: 2) {
    view.alpha = 1.0
}.start {
    debugPrint("Animation finished")
}

LinkedList implementation

.goodswift allows you to use default implementation of LinkedList (Queue, FIFO). Wiki

let queue = LinkedList<Int>()

print(queue.isEmpty)            // true

queue.push(1)                   // [1]
queue.push(2)                   // [1, 2]
queue.push(3)                   // [1, 2, 3]

print(queue.contains(1))        // true
print(queue.filter { $0 > 1 })  // [2, 3]
print(queue.map { $0 + 2 })     // [3, 4, 5]
print(queue.pop())              // Optional(1)
print(queue.pop())              // Optional(2)
print(queue.isEmpty)            // false
print(queue.peak())             // Optional(3)
print(queue.pop())              // Optional(3)
print(queue.isEmpty)            // true

Author

Marek Spalek, [email protected]

Contributors

Pavol Kmet, [email protected]

Tomas Gibas, [email protected]

Dominik Petho, [email protected]

License

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