https://github.com/goodrequest/goodswift
Some good swift extensions, handfully crafted by GoodRequest team.
https://github.com/goodrequest/goodswift
ios swift
Last synced: 9 months ago
JSON representation
Some good swift extensions, handfully crafted by GoodRequest team.
- Host: GitHub
- URL: https://github.com/goodrequest/goodswift
- Owner: GoodRequest
- License: mit
- Created: 2017-02-21T19:06:45.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-06-29T07:55:56.000Z (over 3 years ago)
- Last Synced: 2025-06-26T16:06:02.847Z (9 months ago)
- Topics: ios, swift
- Language: Swift
- Size: 79.1 KB
- Stars: 9
- Watchers: 6
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README

[](http://cocoapods.org/pods/GoodSwift)
[](http://cocoapods.org/pods/GoodSwift)
[](http://cocoapods.org/pods/GoodSwift)
Some good swift extensions, handfully crafted by GoodRequest team.
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Author](#author)
- [License](#license)
## Requirements
- iOS 10.0+
- Xcode 10.0+
- Swift 4.2 (for Swift 4.0 use version 0.9.0)
## Installation
**.good**swift is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:
```ruby
pod 'GoodSwift'
```
## Usage
### Mapping
**.good**swift allows you to easily decode JSON objects from [Alamofire](https://github.com/Alamofire/Alamofire) responses using [Unbox](https://github.com/JohnSundell/Unbox) decoder. You can see examples how to map your model in [Unbox readme](https://github.com/JohnSundell/Unbox/blob/master/README.md).
```swift
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.
```swift
import Alamofire
import GoodSwift
Alamofire.request("https://httpbin.org/get").unbox(completion: { (response: DataResponse) 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 **.good**swift using [CocoaPods](http://cocoapods.org) you need to add flag `DEBUG` manually into `Active Compilation Conditions` in **.good**swift 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`.
```ruby
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:
```swift
UIView.animationChain.animate(withDuration: 2) {
view.alpha = 0.0
}.animate(withDuration: 2) {
view.alpha = 1.0
}.start {
debugPrint("Animation finished")
}
```
### LinkedList implementation
**.good**swift allows you to use default implementation of `LinkedList` (Queue, FIFO).
[Wiki](https://en.wikipedia.org/wiki/Linked_list)
```swift
let queue = LinkedList()
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, marek.spalek@goodrequest.com
## Contributors
Pavol Kmet, pavol.kmet@goodrequest.com
Tomas Gibas, tomas.gibas@goodrequest.com
Dominik Petho, dominik.petho@goodrequest.com
Filip Sasala, filip.sasala@goodrequest.com
## License
**.good**swift is available under the MIT license. See the LICENSE file for more info.