GoodSwift 0.5.0

GoodSwift 0.5.0

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

Maintained by Marek Spalek.


Downloads

Total91
Week10
Month22

Installs

Apps5
Apps WeekApps This Week 2
Test Targets1
Test WeekTests This week 1
powered by Segment

GitHub

Stars3
Watchers1
Forks0
Issues0
Contributors1
Pull Requests0

Code

Files1
SizeIntegration Size 24 kb
LOCLines of Code 194


 
Depends on:
Alamofire~> 4.4
Unbox~> 2.4
 

GoodSwift 0.5.0

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

Author

Marek Spalek, [email protected]

License

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