Skip to content

b9swift/AssociatedObject

Repository files navigation

B9AssociatedObject

Swift Version Swift Package Manager Build Status gitee 镜像

Objective-C associated value wrapper for convenient use in Swift. It is primarily used to add attributes to existing types through extensions.

Installation

You can use either Swift Package Manager or manual importing to add this package to your project.

你也可以使用 gitee 镜像

Usage

You can define extended properties like below. All kinds of Swift types are also supported, not only Objective-C objects.

import B9AssociatedObject

private let fooAssociation = AssociatedObject<String>()
extension SomeObject {
    var foo: String? {
        get { fooAssociation[self] }
        set { fooAssociation[self] = newValue }
    }
}