目录
目录README.md

swift-capture

SwiftPM 5.3 @maximkrouk

A mechanism for safe capturing & weakifying objects in Swift.

Usage Examples

Without Capture
With Capture

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(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)

Weak assign

{ [weak self] value in 
    self?.value = value
}
captureAssign(to: \.value)
captureAssign(to: \.value, removeDuplicates: ==)

Installation

Basic

You can add weak 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.

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

.package(
  name: "weak",
  url: "git@github.com:capturecontext/swift-capture.git",
  .upToNextMajor("2.0.0")
)

Do not forget about target dependencies:

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

License

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

关于
46.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号