GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - khamitimur/AmazingEvent: Generic and retention cycle free Event that enables instance of any type to notify multiple classes when something of interest occurs.

BranchesTags
Open more actions menu

Latest commit

 

History

12 Commits
12 Commits

Folders and files

NameName
Last commit message
Last commit date
Sources/AmazingEvent
Sources/AmazingEvent
 
 
Tests/AmazingEventTests
Tests/AmazingEventTests
 
 
.gitignore
.gitignore
 
 
AmazingEvent.podspec
AmazingEvent.podspec
 
 
LICENSE
LICENSE
 
 
Package.swift
Package.swift
 
 
README.md
README.md
 
 

Repository files navigation

AmazingEvent

AmazingEvent is a generic and retention cycle free Event that enables instance of any type to notify multiple classes when something of interest occurs.

In other words, it's an attempt to bring C# like Event to Swift and exploring what Swift version of Target-Action is like.

Usage

The type that sends an Event is called the publisher and the classes that handle an Event are called subscribers.

Publisher

import AmazingEvent

class Car {
    // It's better to keep an event publisher private if you don't want it to be invoked by some other class.
    private var didStartPublisher = AmazingEventPublisher<Date>()
    
    // On initialization AmazingEventPublisher creates assosiated AmazingEvent.
    // Your job is to make this assosiated event reachable without exposing an event publisher itself.
    private(set) lazy var didStart = didStartPublisher.event
    
    // ...
    
    func start() {
        // Invokes the event by passing `self` as a sender.
        didStartPublisher.invoke(sender: self, parameter: Date())
    }
}

Subscriber

import AmazingEvent

class CarTestBench {
    init(car: Car) {
        car.didStart.subscribe(target: self, handleAction: CarTestBench.carDidStart)
    }
    
    private func carDidStart(sender: AnyObject?, parameter: Date) {
        // ...
    }
}

Requirements

  • macOS 10.14+
  • iOS 11.0+
  • tvOS 11.0+
  • watchOS 4.0+
  • Xcode 11+
  • Swift 5.0+

Installation

CocoaPods

To integrate AmazingEvent into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'AmazingEvent', '~> 2.0'

Swift Package Manager

To integrate AmazingEvent into your Xcode project using Swift Package Manager, specify it as dependency in your Package.swift:

dependencies: [
    .package(url: "https://github.com/khamitimur/AmazingEvent.git", .upToNextMajor(from: "2.0.0"))
]

License

This project is licensed under the MIT License.

Acknowledgments

  • Inspired by article by Colin Eberhardt.

About

Generic and retention cycle free Event that enables instance of any type to notify multiple classes when something of interest occurs.

Topics

curried-functionsevent-patterniosswift

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.