https://github.com/maximkrouk/convenience
Useful extensions, classes and protocols for swift applications. (beta)
https://github.com/maximkrouk/convenience
cocoapods convenience decoding extensions hex protocols regex swift swift5-1 validators xcode11
Last synced: 4 months ago
JSON representation
Useful extensions, classes and protocols for swift applications. (beta)
- Host: GitHub
- URL: https://github.com/maximkrouk/convenience
- Owner: maximkrouk
- License: mit
- Created: 2019-08-01T22:24:28.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-14T11:39:36.000Z (over 5 years ago)
- Last Synced: 2025-02-11T17:47:21.370Z (5 months ago)
- Topics: cocoapods, convenience, decoding, extensions, hex, protocols, regex, swift, swift5-1, validators, xcode11
- Language: Swift
- Homepage:
- Size: 203 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Convenience
**The most convenient framework for your apps.**
[](https://travis-ci.org/maximkrouk/Convenience) [](https://cocoapods.org/pods/Convenience) [](https://cocoapods.org/pods/Convenience) [](https://cocoapods.org/pods/Convenience)
## The story
Programming is all about data. We modify data, store it, share it. You can see it in every app you do. So I've got enaugh writing the same code for decoding data, unwrapping optionals, subscripting collections and decided to... Use one folder called "Reusable" with all this stuff. And migrate it from project to project...
One day The Problem appeared. When you add anything to this folder in a new project, changes are not applied to the older ones. Xcode folder references could have solve this problem, but what if you have to work from remote and have no access to the folder?
So I decided to write this framework and share it with world. I'm gonna try make it as clean as I can, but if You find any garbage here - let me know c:
## Usage
### Bool
- __Toggle__
`Bool().toggled == !Bool`
### CharacterSet
- __ExpressibleByStringLiteral__
`let frameworkName = "Convenience" // == CharacterSet(charactersIn: "Convenience")`
- __Static factory__
`.binaryDigits`
`.hexDigits`
### Codable
- __Convenient coding__
`Encodable.encode(using encoder: ConvenientEncoder = JSONEncoder())`
`Decodable.decode(from data: Data, using encoder: ConvenientEncoder = JSONEncoder())`
### Collection
- __Safe subscripting__
`[1 ,2, 3][safe: 10] == nil`
- __Int-ranged subscripting__ _for bidirectional collecions_
`"String"[0] == "S"`
`"String"[1..<3] == "tr"`
`"String"[3...] == "ing"`
...
### Colors
- __Hex color converting__ _for NS and UI Colors_
`[NS/UI]Color(hex: "#FA6878AA")`
`[NS/UI]Color(hex: "#FA6878")`
`[NS/UI]Color(hex: "FA6878")`
`[NS/UI]Color(rgb: 0xfa6878ff)` _( from hex Int )_
`[NS/UI]Color(rgb: 0xFA6878)`
### Data
- __Decoding__
```swift
let decoding = Data().decode(to: SomeDecodable.self)
decoding.value // SomeDecodable?
switch decoding {
case .success(let value):
return value // SomeDecodable
case .failure(let error):
vc.showAlert(with: error) // for ex.
}
```- __Getting a string__
`Data().string(using: .ascii)`
`Data().string()` _(UTF-8)_
### Error
- __Collect__
```swift
// for now works only for () -> Void funtions
func someThrowable() throws {}
let errors: ErrorBag = Error.collect {
someThrowable
someThrowable
someThrowable
}
/* ==
collect {
someThrowable
someThrowable
someThrowable
}
*/
print(errors.localizedDescription)
// ==
errors.contents.forEach {
print($0.localizedDescriprion)
}
```
### Optional
- __Example__
```swift
let a: Int? = 1 // a == 1
a.isNil // false
a.release() // a == nil
a.isNil // true
let b = a.unwrap(default: 3) // a == nil, b == 3
let c: SomeProtocol? = SomeInstance()
let d = c.cast(to: SomeInstance.self, default: SomeInstance())
```
### NSLock
### NSRegularExpression (Regex)
### RawRepresentable
### Cast
### Modifications
### String (ns, url, regex, crypto)
### Protocols (TypeErasable, StaticNamedType)
### PlainError
----
_( + Working on new features and xcode docs (guess 90% done), github documentation will be provided later.)_
## Requirements
- 📱 iOS 8.0+
## Installation
#### SwiftPM
#### CocoaPods
__Convenience__ is available through [CocoaPods](https://cocoapods.org). To install it, simply add the following line to your Podfile:
```ruby
pod 'Convenience'
```and run `pod install` from the terminal.
## License
Convenience is available under the MIT license. See the LICENSE file for more info.
----
*Feel free to contribute or [communicate](https://twitter.com/mxcat_). I'm open to your ideas.* 🌝