CombinationGenerator 0.2.0

CombinationGenerator 0.2.0

Maintained by Franciso Javier Trujillo Mata.



  • By
  • Francisco Javier Trujillo Mata

CombinationGenerator

Build Status Version License Platform Readme Score

Overview

CombinationGenerator basically is a helper that use brute-force to generate all possibilities for a concrete DataModel given a list of possible values per property. CombinationGenerator use Generics, so it makes your life even easier.

Example

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

Requirements

Is valid for iOS 9 and higher. Requires Swift 5.0 and XCode 10.0 or higher.

Installation

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

pod 'CombinationGenerator'

How to use it

You can just use pod try and inside you will see an example of a ViewController that generate all possbility for the typical UserInfo data model.

pod  try 'CombinationGenerator'

If you don't have pod try installed go to https://github.com/CocoaPods/cocoapods-try to install it.

In case that you still want to see here how it works, keep reading :)

An example used to be easier to understand than 1000 words.. so:

1. Import CombinationGenerator

import CombinationGenerator

2. Create your Data model

class UserInfo {
    var name: String?
    var surname: String?
    var age: Int?
}

3. Instanciate, add combination and generate all the possibilities

let generator = Generator<UserInfo>()
generator.addCombination(propertyKey: "name", values: ["Tete", "MadMoc", "Pableras", "Trujy"])
generator.addCombination(propertyKey: "surname", values: ["Molon", "Singular", "Friendly"])
generator.addCombination(propertyKey: "age", values: [18, 33, 40])


let possibilities = generator.generateCombinations()

4. Results:

In the previous example if we want to see the generated object we can do:

possibilities.forEach { userInfo in
    print(userInfo.name!, userInfo.surname!, userInfo.age!.description)
}

And the received output:

Tete Molon 18
Tete Singular 18
Tete Friendly 18
MadMoc Molon 18
MadMoc Singular 18
MadMoc Friendly 18
Pableras Molon 18
Pableras Singular 18
Pableras Friendly 18
Trujy Molon 18
Trujy Singular 18
Trujy Friendly 18
Tete Molon 33
Tete Singular 33
Tete Friendly 33
MadMoc Molon 33
MadMoc Singular 33
MadMoc Friendly 33
Pableras Molon 33
Pableras Singular 33
Pableras Friendly 33
Trujy Molon 33
Trujy Singular 33
Trujy Friendly 33
Tete Molon 40
Tete Singular 40
Tete Friendly 40
MadMoc Molon 40
MadMoc Singular 40
MadMoc Friendly 40
Pableras Molon 40
Pableras Singular 40
Pableras Friendly 40
Trujy Molon 40
Trujy Singular 40
Trujy Friendly 40

Well Done!

Author

Francisco Javier Trujillo Mata, [email protected]

License

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