Swiftpack.co - maximkrouk/Weak as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
maximkrouk/Weak
A mechanism for safe capturing & weakifying objects in Swift.
.package(url: "https://github.com/maximkrouk/Weak.git", from: "1.0.0")

Weak

SwiftPM 5.3 @maximkrouk

A mechanism for safe capturing & weakifying objects in Swift.

Usage Examples

Without Weak
With Weak

Default

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

Multiple parameters

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

Methods

{ [weak self] in 
    guard let self = self else { return }
    self.someMethod()
}
capture(in: Self.someMethod)

Return values

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

Installation

Basic

You can add DeclarativeConfiguration 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/maximkrouk/weak" 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 DeclarativeConfiguration to your package file. Also my advice is to use SSH.

.package(url: "git@github.com:maximkrouk/weak.git", .branch("main"))

or

.package(url: "git@github.com:maximkrouk/weak.git", .exact("1.0.0"))

Do not forget about target dependencies:

.product(
    name: "Weak", 
    package: "Weak"
)

License

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

GitHub

link
Stars: 1
Last commit: 32 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

1.0.0
32 weeks ago

Initial release

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