New Way Of Working Around With Closures.

Overview

Closured

Swift Platforms CocoaPods Compatible Twitter Build Status

New Way Of Working Around With Closures.

Are you tired of old-school callback closures?

Are you always mess up with capturing references on async closures?

Then Using Closured Will Bring You New Style.

Features

  • Use propertyWrapper To Wrap Closure
  • Captures Weak References Inside Closure
  • Perform Closure On Different Queues
  • Fully Error Handled On Performing Closure
  • Fully Documented With DocC
  • Provide UnitTest

Requirements

Platform Minimum Swift Version Installation Status
iOS 9.0+ 5.3 CocoaPods Tested

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate Closured into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'Closured'

Sample

I have provided one sample project in the repository. To use it clone the repo, Source files for these are in the Example directory in project navigator. Have fun!

Usage

Using Closured is so easy, It uses PropertyWrapper in swift.

You just need to annotate your closures with provided Wrappers.

import Closured

class Example {

	// provide queue or the default is main
	// all the method without queue will use this queue to perform
	@Closured(queue: .main) var voidCallBack: (() -> Void)?
	
	@Closured10(queue: .main) var intCallBack: ((Int) -> Void)?
	
	private func call() {
		try? voidCallBack.sync() // perform on Main Queue
		
		try? voidCallBack.sync(on: .global(.background)) // perform on global Queue
		
		try? voidCallBack.async() // perform on Main Queue
		
		try? voidCallBack.async(on: .global(.utility)) 
		
		
		try? intCallBack.sync(on: .global(.utility), 89) 
		
		try? intCallBack.async(10) // perform on Main Queue
	}
}

class Container {
	
	private let ref = Example()
	
	func bind() {
		ref.$voidCallBack.byWrapping(self) { strongSelf in
			// strongSelf is unwrapped reference to self
			// self is not retained
			// this closure won't be executed if self was deallocated
		}
		
		ref.$intCallBack.byWrapping(self) { strongSelf, integer in
			// strongSelf is unwrapped reference to self
			// self is not retained
			// this closure won't be executed if self was deallocated
			// this closure will be called twice in two different queue, and provide 2 numbers = 89 and 10 
		}
	}
}

Contributors

Feel free to share your ideas or any other problems. Pull requests are welcomed.

License

CocoAttributedStringBuilder is released under an MIT license. See LICENSE for more information.

You might also like...
A Swift micro-framework to easily deal with weak references to self inside closures

WeakableSelf Context Closures are one of Swift must-have features, and Swift developers are aware of how tricky they can be when they capture the refe

Closures based APIs for CoreBluetooth

SwiftyBluetooth Closures based APIs for CoreBluetooth. Features Replace the delegate based interface with a closure based interface for every CBCentra

A result builder that allows to define shape building closures
A result builder that allows to define shape building closures

ShapeBuilder A result builder implementation that allows to define shape building closures and variables. Problem In SwiftUI, you can end up in a situ

A Swift micro-framework to easily deal with weak references to self inside closures

WeakableSelf Context Closures are one of Swift must-have features, and Swift developers are aware of how tricky they can be when they capture the refe

Define and chain Closures with Inputs and Outputs

Closure Define and chain Closures with Inputs and Outputs Examples No Scoped State let noStateCount = ClosureString, String { text in String(repea

A property wrapper to enforce that closures are called exactly once!

A property wrapper that allows you to enforce that a closure is called exactly once. This is especially useful after the introduction of SE-0293 which makes it legal to place property wrappers on function and closure parameters.

Extensions which helps to convert objc-style target/action to swifty closures

ActionClosurable Usage ActionClosurable extends UIControl, UIButton, UIRefreshControl, UIGestureRecognizer and UIBarButtonItem. It helps writing swift

Swift extension which adds start, animating and completion closures for CAAnimation objects. Aka, CAAnimation + Closure / Block
Swift extension which adds start, animating and completion closures for CAAnimation objects. Aka, CAAnimation + Closure / Block

Swift-CAAnimation-Closure Swift extension which adds start, animating and completion closures for CAAnimation objects. Aka, CAAnimation + Closure or C

T - A simple testing framework using closures and errors

t Quickly test expectations What is t? t is a simple testing framework using clo

Chain multiple UIView animations without endlessly nesting in completion closures.
Chain multiple UIView animations without endlessly nesting in completion closures.

⛓ Chain multiple UIView animations without endlessly nesting in completion closures. Used in some of the more superfluous animations in the OK Video app.

SugarRecord is a persistence wrapper designed to make working with persistence solutions like CoreData in a much easier way.
SugarRecord is a persistence wrapper designed to make working with persistence solutions like CoreData in a much easier way.

What is SugarRecord? SugarRecord is a persistence wrapper designed to make working with persistence solutions like CoreData in a much easier way. Than

A concise Mantle-like way of working with Realm and JSON.

Realm+JSON A concise Mantle-like way of working with Realm and JSON. Breaking Change Method - deepCopy replaces the previous functionality of - shallo

🌳 Environment – a nicer, type-safe way of working with environment variables in Swift.

🌳 Environment Welcome to Environment – a nicer, type-safe way of working with environment variables in Swift. Usage Access Environment Variables The

A library of data structures for working with collections of identifiable elements in an ergonomic, performant way.
A library of data structures for working with collections of identifiable elements in an ergonomic, performant way.

Swift Identified Collections A library of data structures for working with collections of identifiable elements in an ergonomic, performant way. Motiv

Discover new programming concepts and more new SwiftUI 2 features in this section

Africa-Zoo One thing is sure, we will discover new programming concepts and more new SwiftUI 2 features in this section. TOPICS ARE COVERED: JSON with

Music Room: a mobile app that offers a new way of experiencing music
Music Room: a mobile app that offers a new way of experiencing music

🎼 Music Room - 42 School Project 🎸 🤳🏻 Music Room is a mobile app that offers

A powerful new way to Reddit on iOS.

Slide for Reddit Slide is a powerful open-source, ad-free, Swift-based Reddit browser for iOS. Feel free to join us on the official subreddit for disc

ReleaseNotesKit - a brand new, elegant, and extremely simple way to present the recent version’s release notes to your users
ReleaseNotesKit - a brand new, elegant, and extremely simple way to present the recent version’s release notes to your users

ReleaseNotesKit This is ReleaseNotesKit, a brand new, elegant, and extremely simple way to present the recent version’s release notes to your users. R

Spin aims to provide a versatile Feedback Loop implementation working with the three main reactive frameworks available in the Swift community (RxSwift, ReactiveSwift and Combine)
Spin aims to provide a versatile Feedback Loop implementation working with the three main reactive frameworks available in the Swift community (RxSwift, ReactiveSwift and Combine)

With the introduction of Combine and SwiftUI, we will face some transition periods in our code base. Our applications will use both Combine and a thir

Releases(1.0.0)
Owner
Kiarash Vosough
Kiarash Vosough
An introduction to using Swift's new concurrency features in SwiftUI

SwiftUI Concurrency Essentials An introduction to using Swift's new concurrency features in SwiftUI Discuss with me · Report Bug · Request Feature Art

Peter Friese 80 Dec 14, 2022
GroupWork is an easy to use Swift framework that helps you orchestrate your concurrent, asynchronous functions in a clean and organized way

GroupWork is an easy to use Swift framework that helps you orchestrate your concurrent, asynchronous functions in a clean and organized way. This help

Quan Vo 42 Oct 5, 2022
AwaitKit is a powerful Swift library which provides a powerful way to write asynchronous code in a sequential manner.

AwaitKit is a powerful Swift library inspired by the Async/Await specification in ES8 (ECMAScript 2017) which provides a powerful way to write asynchronous code in a sequential manner.

Yannick Loriot 752 Dec 5, 2022
Egg Timer app helps you to cook your egg in the way you want

Egg Timer Egg Timer app helps you to cook your egg in the way you want. You need to decide on how do you want to eat your egg than just click the egg

Emrullah Cirit 2 Nov 29, 2022
AsyncButton is the simple way to run concurrent code in your views.

SwiftUI AsyncButton ??️ AsyncButton is a Button capable of running concurrent code. Usage AsyncButton has the exact same API as Button, so you just ha

Lorenzo Fiamingo 13 Dec 14, 2022
A wrapper around UICollectionViewController enabling a declarative API around it's delegate methods using protocols.

Thunder Collection Thunder Collection is a useful framework which enables quick and easy creation of collection views in iOS using a declarative appro

3 SIDED CUBE 4 Nov 6, 2022
SwiftyBluetooth - Closures based APIs for CoreBluetooth.

SwiftyBluetooth Closures based APIs for CoreBluetooth. Features Replace the delegate based interface with a closure based interface for every CBCentra

Jordane Belanger 181 Jan 2, 2023
Replacement for Apple's Reachability re-written in Swift with closures

Reachability.swift Reachability.swift is a replacement for Apple's Reachability sample, re-written in Swift with closures. It is compatible with iOS (

Ashley Mills 7.7k Jan 1, 2023
Swifty closures for UIKit and Foundation

Closures is an iOS Framework that adds closure handlers to many of the popular UIKit and Foundation classes. Although this framework is a substitute f

Vinnie Hesener 1.7k Dec 21, 2022