Outfit 0.1.0

Outfit 0.1.0

Maintained by Oleksii Faizullov.



Outfit 0.1.0

  • By
  • fuzza

Outfit

CI Status Version License Platform

Usage

Basic usage

  1. Import the framework
import Outfit
  1. Define conformance of your class to Outfitable protocol
extension MyCustomView: Outfitable {}
  1. Extend your wardrobe with some nice outfit
extension Wardrobe where Wearer: MyCustomView {

    func perfectLook() -> Outfit<Wearer> {
        return { 
            // Customize the instance of MyCustomView
            $0.titleColor = .red
            $0.placeholder = "It's something new"
            $0.clipsToBounds = true
        }
    }
}
  1. Access your wardrobe and try it on
let view = MyCustomView()

view.wrd.tryOn { 
    $0.perfectLook() 
}
  1. Have fun!

Advanced usage

Outfit composition

You can combine outfits together using custom concat operator (++)

extension Wardrobe where Wearer: UIView {
    func rounded(_ radius: CGFloat) -> Outfit<Wearer> {
        return {
            $0.layer.masksToBounds = true
            $0.layer.cornerRadius = radius
        }
    }
  
    func background(_ color: UIColor) -> Outfit<Wearer> {
        return { $0.backgroundColor = color }
    }

    func defaultView() -> Outfit<Wearer> {
        return rounded(5.0)
        ++ background(.white)
    }
}

Reuse outfits in subclasses

You can reuse outfits from parent class in the child

extension Wardrobe where Wearer: UIView {
    func defaultView() -> Outfit<Wearer> { ... }
}

extension Wardrobe where Wearer: UIButton {
    func title(_ text: String) -> Outfit<Wearer> {
        return {
            $0.setTitle(text, for: .normal)
        }
    }

    func defaultButton() -> Outfit<Wearer> {
        return defaultView()
            ++ title("Default title")
    }
}

Override default properties

If you need to override some property in a single place or add new one, and it doesn't make a sense to define new function for this:

func viewDidLoad() {
    super.viewDidLoad()

    let view = MyCustomView()
    view.wrd.tryOn {
        $0.perfectLook()
        ++ { $0.titleColor = .green }
    }
}

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • Swift 4.2
  • Xcode 10

Installation

Outfit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Outfit'

Author

Oleksii Faizullov, [email protected]

License

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