All Projects → bannzai → Inu

bannzai / Inu

Licence: MIT license
Easily way to write a control logic for call once function in instance.

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language

Inu

Easily way to write a control logic for call once function in instance.

Usage

To support call once, a class needs to implement the OnceType

class ViewController: UIViewController, OnceType { 
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

You can use once property. And once using call() method. call() is called only sometimes in same function.

func anyFunction() {
  once.call() {
      print("This statement is call once while self live")
  }
  once.call() {
      fatalError("Not call this statemenet")
  }
}

If want to call once again. You should call clearAll() method. clearAll() is clear all cache. You can same call() one more time.

func callOneMoreTime() {
    once.clearAll()
    anyFunction() // <-  This statement is call once while self live
}

It's also possible to control call() with string key. And you can use clear(withKey: String) method.

func callingWithKey() {
    once.call("key") {
        print("Calling")
    }
    once.call("key") {
        fatalError("Not Call")
    }
    once.call() {
        print("Calling")
    }
    once.clear(withKey: "key")
    once.call("key") {
        print("Calling")
    }
    once.call() {
        fatalError("Not Call")
    }
}

License

Inu is released under the MIT license. See LICENSE.txt for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].