Convenience 0.3.3

Convenience 0.3.3

Maintained by mxcat..



Convenience

The most convenient framework for your apps.

CI Status Version License Platform

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

    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

    // 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

    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. To install it, simply add the following line to your Podfile:

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. I'm open to your ideas. 🌝