Swiftpack.co - CaptureContext/swift-capture as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by CaptureContext.
CaptureContext/swift-capture 3.0.1
A mechanism for safe capturing & weakifying objects in Swift.
⭐️ 7
🕓 25 weeks ago
.package(url: "https://github.com/CaptureContext/swift-capture.git", from: "3.0.1")

swift-capture

test SwiftPM 5.9 Platforms docs @capture_context

A mechanism for ergonomic and safe capturing & weakifying objects in Swift.

Usage Examples

Without Capture
With Capture

Default

{ [weak self] in 
  guard let self else { return }
  /// ...
}
capture { _self in
  /// ...
}

Multiple parameters

{ [weak self] a, b, c in 
  guard let self else { return }
  /// ...
}
capture { _self, a, b, c in 
  /// ...
}

Methods

{ [weak self] in 
  guard let self = self else { return }
  self.someMethod()
}
capture(in: <#Type#>.someMethod)

Return values

let object.dataSource = { [weak self] in
  guard let self = self else { return [] }
  return self.data
}
let object.dataSource = capture(orReturn: [], in: \.data)

Installation

Basic

You can add swift-capture to an Xcode project by adding it as a package dependency.

  1. From the File menu, select Swift Packages › Add Package Dependency…
  2. Enter "https://github.com/capturecontext/swift-capture" into the package repository URL text field
  3. Choose products you need to link them to your project.

Recommended

If you use SwiftPM for your project, you can add weak to your package file. Also my advice is to use SSH.

.package(
  url: "[email protected]:capturecontext/swift-capture.git",
  .upToNextMajor("3.0.0")
)

Do not forget about target dependencies:

.product(
    name: "Capture", 
    package: "swift-capture"
)

License

This library is released under the MIT license. See LICENSE for details.

GitHub

link
Stars: 7
Last commit: 24 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

3.0.1
25 weeks ago

Minor fixes with no impact on API

  • Use .git protocol extension for docc-plugin link
  • Fix test badge link in readme

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics