https://github.com/vsanthanam/weakreference
An existential weak reference wrapper for Swift
https://github.com/vsanthanam/weakreference
ios macos spm swift tvos watchos weak xcode
Last synced: 8 months ago
JSON representation
An existential weak reference wrapper for Swift
- Host: GitHub
- URL: https://github.com/vsanthanam/weakreference
- Owner: vsanthanam
- License: mit
- Created: 2022-04-19T18:50:58.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-30T15:01:30.000Z (12 months ago)
- Last Synced: 2025-07-13T21:51:24.500Z (8 months ago)
- Topics: ios, macos, spm, swift, tvos, watchos, weak, xcode
- Language: Swift
- Homepage: https://weak.tools
- Size: 219 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# WeakReference
[](https://github.com/vsanthanam/WeakReference/blob/main/LICENSE)
[](https://github.com/vsanthanam/WeakReference/releases)
[](https://github.com/vsanthanam/WeakReference/actions)
[](https://swift.org)
[](https://developer.apple.com)
An existential weak reference.
Use this wrapper class to pass around weakly-referenced instances of an object.
## Installation
WeakReference is currently distributed exclusively through the [Swift Package Manager](https://www.swift.org/package-manager/).
To add WeakReference as a dependency to an existing Swift package, add the following line of code to the `dependencies` parameter of your `Package.swift` file:
```swift
dependencies: [
.package(
url: "https://github.com/vsanthanam/WeakReference.git",
from: "2.0.0"
)
]
```
To add WeakReference as a dependency to an Xcode Project:
* Choose `File` → `Add Packages...`
* Enter package URL `https://github.com/vsanthanam/WeakReference.git` and select your release and of choice.
Other distribution mechanisms like CocoaPods or Carthage may be added in the future.
Additional installation instructions are available on the [Swift Package Index](https://swiftpackageindex.com/vsanthanam/WeakReference)
[](https://swiftpackageindex.com/vsanthanam/WeakReference)
[](https://swiftpackageindex.com/vsanthanam/WeakReference)
## Usage
```swift
import WeakReference
var obj: MyObj? = .init( ... )
let weakReference = weak(obj!)
assert(weakReference.obj != nil)
obj = nil
assert(weakReference.obj == nil)
```
See the [complete documentation](https://weak.tools/docs/documentation/weakreference/) for more information.
## License
**WeakReference** is available under the MIT license. See the LICENSE file for more information.