Swiftpack.co - Package - MakeupStudio/swift-declarative-configuration

Swift Declarative Configuration

Swift SwiftPM 5.3 @maximkrouk

Swift Declarative Configuration (SDC, for short) is a tiny library, that enables you to configure your objects in a declarative, consistent and understandable way, with ergonomics in mind. It can be used to configure any objects on any platform, including server-side-swift.


  • FunctionalModification

    Provides modification functions for copying and modifying immutable stuff. It is useful for self-configuring objects like builder, when modificating methods should return modified self

  • FunctionalKeyPath & CasePaths

    KeyPath functional wrappers, one is generalized and the other is for enums. CasePath is a dependency.

  • FunctionalConfigurator

    Funtional configurator for anything, enables you to specify modification of an object and to apply the modification later.

    Also contains self-implementing protocols (ConfigInitializable, CustomConfigurable) to enable you add custom configuration support for your types (NSObject already conforms to it for you).

  • FunctionalBuilder

    Functional builder for anything, enables you to modify object instances in a declarative way. Also contains BuilderProvider protocol with a computed builder property and implements that protocol on NSObject type.

  • DeclarativeConfiguration

    Wraps and exports all the products.

Basic Usage

UIKit & No SDC

class ImageViewController: UIViewController {
    let imageView = UIImageView()
    override func loadView() {
        self.view = imageView
    override func viewDidLoad() {
        imageView.contentMode = .scaleAspectFit
        imageView.backgroundColor = .black
        imageView.layer.masksToBounds = true
        imageView.layer.cornerRadius = 10

UIKit & FunctionalConfigurator

import FunctionalConfigurator

class ImageViewController: UIViewController {
    let imageView = UIImageView { $0 
    override func loadView() {
        self.view = imageView

Note: This way is recommended, but remember, that custom types MUST implement initializer with no parameters even if the superclass already has it or you will get a crash otherwise.

UIKit & FunctionalBuilder

import FunctionalBuilder

class ImageViewController: UIViewController {
    let imageView = UIImageView().builder
    override func loadView() {
        self.view = imageView

Note: This way is recommended too, and it is more safe, because it modifies existing objects.

Other usecases


Customize any object by passing initial value to a builder

let object = Builder(Object())
    .build() // Returns modified object

For classes you can avoid returning a value by calling apply method, instead of build

let _class = _Class()
    .apply() // Returns Void

Conform your own types to BuilderProvider protocol to access builder property.

import CoreLocation
import DeclarativeConfiguration

extension CLLocationCoordinate2D: BuilderProvider {}
// Now you can access `location.builder.latitude(0).build()`


README PLACEHOLDER (Not yet written 😅)



You can add DeclarativeConfiguration to an Xcode project by adding it as a package dependency.

  1. From the File menu, select Swift Packages › Add Package Dependency…
  2. Enter "https://github.com/makeupstudio/swift-declarative-configuration" into the package repository URL text field
  3. Choose products you need to link them to your project.


If you use SwiftPM for your project, you can add DeclarativeConfiguration to your package file. Also my advice will be to use SSH.

    url: "git@github.com:makeupstudio/swift-declarative-configuration.git", 
    from: "0.0.4"

Do not forget about target dependencies:

    name: "DeclarativeConfiguration", 
    package: "swift-declarative-configuration"


This library is released under the MIT license. See LICENSE for details.


Stars: 8

Used By

Total: 0


DeclarativeConfiguration - 2020-10-18 00:20:07

This release brings enough cool stuff and makes the API mature enough to be stable.

DeclarativeConfiguration - 2020-09-20 17:05:33

This release includes:

  • Modification
  • FunctionalKeyPath
  • Configurator
  • Builder
  • CasePath dependency