GoodSwift 0.10.1

GoodSwift 0.10.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jun 2022
SPMSupports SPM

Maintained by Marek Spalek.



 
Depends on:
Alamofire~> 5.4
Unbox~> 3.0
 

GoodSwift 0.10.1

.goodswift

Version License Platform

Some good swift extensions, handfully crafted by GoodRequest team.

Requirements

  • iOS 10.0+
  • Xcode 10.0+
  • Swift 4.2 (for Swift 4.0 use version 0.9.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]

Filip Sasala, [email protected]

License

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