Pledge A thoughtfully designed reactive programming framework in Swift Pledge is a lightweight, thread-safe reactive programming framework for Swift that simplifies state management, event propagation and balances power with simplicity in your applications. While other frameworks force you to learn complex concepts and operators, Pledge focuses on solving the real problems developers face daily: Overview Pledge provides a clean, flexible way to implement the observer pattern in Swift applications. It enables you to create observable values that notify subscribers of changes, with powerful features like: Thread-safe implementation Priority-based notifications Customizable delivery queues Batch updates Rate limiting (throttling and debouncing) Functional operators (map, filter, etc.) Global state management Installation Swift Package Manager Add the following to your Package.swift file: dependencies: [ . package ( url : " https://github.com/gokulnair2001/Pledge.git " , from : " 1.0.0 " ) ] Core Components PLObservable PLObservable is the heart of Pledge, representing a thread-safe container for a value that can be observed for changes. // Create an observable string let messageObservable = PLObservable ( " Hello " ) // Subscribe to changes let subscription = messageObservable . subscribe { newMessage in print ( " Message changed to: \( newMessage ) " ) } // Update the value messageObservable . setValue ( " Hello World " ) PLGlobalStore PLGlobalStore provides a centralized repository for observables, acting as a lightweight state management solution. // Access shared instance let store = PLGlobalStore . shared // Get or create an observable let userNameObservable = store . string ( for : " userName " , defaultValue : " Guest " ) // Subscribe to changes userNameObservable . subscribe { name in print ( " User name is now: \( name ) " ) } // Update from anywhere in your app PLGlobalStore . shared . string ( for : " userName " ) . setValue ( " John " ) How Observables Work...
First seen: 2025-04-10 16:45
Last seen: 2025-04-10 19:45