Git Product home page Git Product logo

selector-closure's Introduction

Moved to https://github.com/mithyer/Ralyo/tree/master/src/Extension/Selector-Closure

Selector-Closure

Swift32 Swift4 Platform

Selector-Closure is a light way to convert objc target-action selector to closure style

Version 1.x.x

Type of Object calling "sce" will be auto recognized in closure

UIControl

use ".sce" to make closure callback

let btn = UIButton()
let field = UITextField()

// for specific event 
_ = btn.sce.add(.touchUpInside) { sender in
  // ... sender is UIButton
}

// for default event(UIButton, UISwitch, UISlider, UITextField has default events)
let invoker = field.sce.add { sender in
  // ... sender is UITextField
}

// now you can remove action with invoker returned
field.sce.remove(invoker)

// remove all for events
field.sce.removeAll(.touchUpInside) { sender in
  // ...
}

// test didAdd events
let res: Bool = field.sce.didAdd(.touchUpInside)

UIBarButtonItem

use ".SCE" to initialize

let item = UIBarButtonItem.SCE.initialize(title: "test", style: .plain, { item in
  // ...
})

// ...

UIGestureRecognizer

use ".SCE" to initialize

// init a recognizer, 
let tgr = UITapGestureRecognizer.SCE.initialize { tgr in
  // tgr is UITapGestureRecognizer
}

let sgr = UISwipeGestureRecognizer.SCE.initialize { sgr in
  // sgr is UISwipeGestureRecognizer
}

UIView

use ".sce" to make closure callback

// fast make tap action
let view = UIView()
let tapGestureRecognizer = view.sce.whenTapped { tgr in
  // tgr === tapGestureRecognizer
}

Convert your own

// you have an instance named obj
let invoker = Invoker(obj) { obj in
  // ...
}
let act = invoker.action // convert done, now pass invoker to target, act to action

selector-closure's People

Contributors

mithyer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.