Skip to content

Tool for split functions on targets. For project with multiple targets.

License

Notifications You must be signed in to change notification settings

zSoNz/TargetBox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TargetBox

CI Status Version License Platform

Tool for split file with two or more targets on independence parts.

Example and explanation on View Controller

First you need to define and inherit from String and Targets Type a new Targets enum:

enum ExampleTargets: String, TargetsType {

    // String version should be the same as target name. It's case sensitive. 
    case targetBox = "TargetBox" 
    case anotherTarget = "AnotherTarget"
}

Then definne functions for each target and add box variable in to controller class:

private var box: TargetsBox<TargetBoxEmulation, ExampleTargets>?

private func prepareTargetBox() {
    print("Hello Box Target")
}

private func prepareForOthers() {
    print("Hello Others Target")
}

Then definne functions like this and call it on init:

private func createTargetBox() {

    // This will create weak reference on function in your controller. 
    let targetBoxFunction = WeakFunction(
        signature: ExampleViewController.prepareTargetBox, 
        object: self
    )
    
    /*
    @param function Created early weak function.
    @param trigger Selector after which our weaked function will be called, function must be dynamic or marked as dynamic
    @param target The target, what be defined early, on which the function should be called
    */
    let containerTargetBox = TargetingFunctionContainer(
        function: targetBoxFunction, 
        trigger: #selector(ExampleViewController.viewDidLoad), 
        target: ExampleTargets.targetBox
    )
    
    let otherTargetFunction = WeakFunction(
        signature: ExampleViewController.prepareForOthers,
        object: self
    )
    
    let containerOthers = TargetingFunctionContainer(
        function: otherTargetFunction,
        trigger: #selector(ExampleViewController.viewDidLoad),
        target: ExampleTargets.anotherTarget
    )
    
    self.box = TargetsBox(containers: [containerTargetBox, containerOthers])
}

And then after someone call your trigger function, weak function be called on your selected target.

Installation

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

pod 'TargetBox'

Author

Kikacheishvili Bogdan, [email protected]

License

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

About

Tool for split functions on targets. For project with multiple targets.

Resources

License

Stars

Watchers

Forks

Packages

No packages published