Skip to content
/ Inu Public

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

License

Notifications You must be signed in to change notification settings

bannzai/Inu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published