EKBuilder 1.0.2

EKBuilder 1.0.2

Maintained by Erik Kamalov.



EKBuilder 1.0.2

  • By
  • Erik Kamalov

Builder

contributions welcome Swift Version CocoaPods Build Status Carthage compatible

The super easy and generic builder pattern. It's easy if you try 💪.

Introduction

Initialize UIView build set its properties. 👍 👍

let label:UIView = .build{
  $0.backgroundColor = .red
  $0.clipsToBounds = true
}

👇 👇 This is equivalent to: 👇 👇

let label: UIView = {
  let view = UIView()
  view.backgroundColor = .red
  view.clipsToBounds = true
  return view
}()

Tips and examples

  • You can use build to all of NSObject subclasses.
    let view = UIView.build { // Example 1
      $0.color = .red
    }
     let view:UIView = .build { (view) in // Example 2
        view.color = .red
     }
     let view:UIView = .build { // Example 2
       $0.color = .red
     }
  • You can use build to all of class and structure. Just make extensions. Init implementation is required for the class, not required for the structure
    extension UserType: EKBuilder {}
    
    let instance:UserType = .build{
      $0.value = "it's easy if you try!"
    }
  • Example: Here's an example usage in an UIViewController subclass.
      class Tesla: EKBuilder {
             var type:String!
             var count:Int!
             required init() {}
      }
      
      struct Audi:EKBuilder {
             var type:String!
             var count:Int!
      }
     
     final class ViewController: UIViewController {
     
       let tesla:Tesla = .build {
         $0.type = "Model X"
         $0.count = 10
       }
     
       let audi = Audi.build {
          $0.type = "R8"
          $0.count = 10
       }
     
       override func viewDidLoad() {
         super.viewDidLoad()
         print(tesla.type, tesla.count)
         print(audi.type, audi.count)
       }
     
     }

Installation

CocoaPods

Add the following entry to your Podfile:

pod 'EKBuilder'

Then run pod install.

Don't forget to import EKBuilder in every file you'd like to use Hero.

Carthage

Add the following entry to your Cartfile:

github "erikkamalov/EKBuilder"

Then run carthage update.

If this is your first time using Carthage in the project, you'll need to go through some additional steps as explained over at Carthage.

License

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