Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mxcl/PromiseKit
Promises for Swift & ObjC.
https://github.com/mxcl/PromiseKit
objc promises swift
Last synced: 3 months ago
JSON representation
Promises for Swift & ObjC.
- Host: GitHub
- URL: https://github.com/mxcl/PromiseKit
- Owner: mxcl
- License: mit
- Created: 2014-04-04T13:54:37.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-04-06T11:04:33.000Z (7 months ago)
- Last Synced: 2024-04-14T12:33:51.601Z (7 months ago)
- Topics: objc, promises, swift
- Language: Swift
- Homepage:
- Size: 9.95 MB
- Stars: 14,178
- Watchers: 252
- Forks: 1,450
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - PromiseKit - Promises for iOS and macOS. (EventBus / Getting Started)
- awesome-swift - PromiseKit - Async promise programming lib. (Libs / Events)
- awesome-swift - PromiseKit - A delightful Promises implementation for iOS. (Extensions)
- awesome-swift - PromiseKit - Async promise programming lib. (Libs / Events)
- awesome-swift - PromiseKit - Promises for asynchronous programming. (Libraries)
- awesome-ios-star - PromiseKit - Promises for iOS and macOS. (EventBus / Getting Started)
- awesome-starts - mxcl/PromiseKit - Promises for Swift & ObjC. (Swift)
- awesome-ios-1 - mxcl / PromiseKit
- fucking-awesome-swift - PromiseKit - Async promise programming lib. (Libs / Events)
- awesome-swift-cn - PromiseKit - async promise programming lib. (Libs / Events)
- Awesome-iOS - PromiseKit - Promises for Swift & ObjC. (Foundation)
- awesome-swift - PromiseKit - Promises for Swift & ObjC. ` π 2 days ago ` (Events [π](#readme))
README
![PromiseKit](../gh-pages/public/img/logo-tight.png)
[![badge-pod][]][cocoapods] ![badge-languages][] ![badge-pms][] ![badge-platforms][] [![codecov](https://codecov.io/gh/mxcl/PromiseKit/branch/master/graph/badge.svg?token=wHSAz7N8WA)](https://codecov.io/gh/mxcl/PromiseKit)
---
Promises simplify asynchronous programming, freeing you up to focus on the more
important things. They are easy to learn, easy to master and result in clearer,
more readable code. Your co-workers will thank you.```swift
UIApplication.shared.isNetworkActivityIndicatorVisible = truelet fetchImage = URLSession.shared.dataTask(.promise, with: url).compactMap{ UIImage(data: $0.data) }
let fetchLocation = CLLocationManager.requestLocation().lastValuefirstly {
when(fulfilled: fetchImage, fetchLocation)
}.done { image, location in
self.imageView.image = image
self.label.text = "\(location)"
}.ensure {
UIApplication.shared.isNetworkActivityIndicatorVisible = false
}.catch { error in
self.show(UIAlertController(for: error), sender: self)
}
```PromiseKit is a thoughtful and complete implementation of promises for any
platform that has a `swiftc`. It has *excellent* Objective-C bridging and
*delightful* specializations for iOS, macOS, tvOS and watchOS. It is a top-100
pod used in many of the most popular apps in the world.[![codecov](https://codecov.io/gh/mxcl/PromiseKit/branch/master/graph/badge.svg)](https://codecov.io/gh/mxcl/PromiseKit)
# Quick Start
In your [Podfile]:
```ruby
use_frameworks!target "Change Me!" do
pod "PromiseKit", "~> 8"
end
```PromiseKit 8 supports recent Xcodes (13+). Some Podspecs were
[dropped as a result](https://github.com/mxcl/PromiseKit/pull/1318).
Pull requests are welcome.PromiseKit 6, 5 and 4 support Xcode 8.3, 9.x and 10.0; Swift 3.1,
3.2, 3.3, 3.4, 4.0, 4.1, 4.2, 4.3 and 5.0 (development snapshots); iOS, macOS,
tvOS, watchOS, Linux and Android; CocoaPods, Carthage and SwiftPM;
([CI Matrix](https://travis-ci.org/mxcl/PromiseKit)).For Carthage, SwiftPM, Accio, etc., or for instructions when using older Swifts or Xcodes, see our [Installation Guide]. We recommend
[Carthage](https://github.com/Carthage/Carthage) or
[Accio](https://github.com/JamitLabs/Accio).# PromiseKit and Swift 5.5+ Async/Await
As of Swift 5.5, the Swift language now offers support for [built-in concurrency with async / await](https://docs.swift.org/swift-book/LanguageGuide/Concurrency.html). See [Async+](https://github.com/async-plus/async-plus) for a port of PromiseKit's most useful patterns to this new paradigm.
# Professionally Supported PromiseKit is Now Available
TideLift gives software development teams a single source for purchasing
and maintaining their software, with professional grade assurances from
the experts who know it best, while seamlessly integrating with existing
tools.[Get Professional Support for PromiseKit with TideLift](https://tidelift.com/subscription/pkg/cocoapods-promisekit?utm_source=cocoapods-promisekit&utm_medium=referral&utm_campaign=readme).
# Documentation
* Handbook
* [Getting Started](Documentation/GettingStarted.md)
* [Promises: Common Patterns](Documentation/CommonPatterns.md)
* [Frequently Asked Questions](Documentation/FAQ.md)
* Manual
* [Installation Guide](Documentation/Installation.md)
* [Objective-C Guide](Documentation/ObjectiveC.md)
* [Troubleshooting](Documentation/Troubleshooting.md) (e.g., solutions to common compile errors)
* [Appendix](Documentation/Appendix.md)
* [API Reference](https://mxcl.dev/PromiseKit/reference/v6/Classes/Promise.html)# Extensions
Promises are only as useful as the asynchronous tasks they represent. Thus, we
have converted (almost) all of Appleβs APIs to promises. The default CocoaPod
provides Promises and the extensions for Foundation and UIKit. The other
extensions are available by specifying additional subspecs in your `Podfile`,
e.g.:```ruby
pod "PromiseKit/MapKit" # MKDirections().calculate().then { /*β¦*/ }
pod "PromiseKit/CoreLocation" # CLLocationManager.requestLocation().then { /*β¦*/ }
```All our extensions are separate repositories at the [PromiseKit organization].
## I don't want the extensions!
Then donβt have them:
```ruby
pod "PromiseKit/CorePromise", "~> 8"
```> *Note:* Carthage installations come with no extensions by default.
## Networking
Promise chains commonly start with a network operation. Thus, we offer
extensions for `URLSession`:```swift
// pod 'PromiseKit/Foundation' # https://github.com/PromiseKit/Foundationfirstly {
URLSession.shared.dataTask(.promise, with: try makeUrlRequest()).validate()
// ^^ we provide `.validate()` so that eg. 404s get converted to errors
}.map {
try JSONDecoder().decode(Foo.self, with: $0.data)
}.done { foo in
//β¦
}.catch { error in
//β¦
}func makeUrlRequest() throws -> URLRequest {
var rq = URLRequest(url: url)
rq.httpMethod = "POST"
rq.addValue("application/json", forHTTPHeaderField: "Content-Type")
rq.addValue("application/json", forHTTPHeaderField: "Accept")
rq.httpBody = try JSONEncoder().encode(obj)
return rq
}
```Support for Alamofire is welcome, please submit a PR.
# Support
Please check our [Troubleshooting Guide](Documentation/Troubleshooting.md), and
if after that you still have a question, ask at our [Gitter chat channel] or on [our bug tracker].## Security & Vulnerability Reporting or Disclosure
https://tidelift.com/security
[badge-pod]: https://img.shields.io/cocoapods/v/PromiseKit.svg?label=version
[badge-pms]: https://img.shields.io/badge/supports-CocoaPods%20%7C%20Carthage%20%7C%20Accio%20%7C%20SwiftPM-green.svg
[badge-languages]: https://img.shields.io/badge/languages-Swift%20%7C%20ObjC-orange.svg
[badge-platforms]: https://img.shields.io/badge/platforms-macOS%20%7C%20iOS%20%7C%20watchOS%20%7C%20tvOS%20%7C%20Linux-lightgrey.svg
[badge-mit]: https://img.shields.io/badge/license-MIT-blue.svg
[OMGHTTPURLRQ]: https://github.com/PromiseKit/OMGHTTPURLRQ
[Alamofire]: http://github.com/PromiseKit/Alamofire-
[PromiseKit organization]: https://github.com/PromiseKit
[Gitter chat channel]: https://gitter.im/mxcl/PromiseKit
[our bug tracker]: https://github.com/mxcl/PromiseKit/issues/new
[Podfile]: https://guides.cocoapods.org/syntax/podfile.html
[PMK6]: http://mxcl.dev/PromiseKit/news/2018/02/PromiseKit-6.0-Released/
[Installation Guide]: Documentation/Installation.md
[badge-travis]: https://travis-ci.org/mxcl/PromiseKit.svg?branch=master
[travis]: https://travis-ci.org/mxcl/PromiseKit
[cocoapods]: https://cocoapods.org/pods/PromiseKit