# AssociatedObject **Repository Path**: b9swift/AssociatedObject ## Basic Information - **Project Name**: AssociatedObject - **Description**: 方便地在 Swift 中利用 Objective-C 关联对象 - **Primary Language**: Swift - **License**: MIT - **Default Branch**: main - **Homepage**: https://github.com/b9swift/AssociatedObject - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-12-28 - **Last Updated**: 2022-12-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # B9AssociatedObject [![Swift Version](https://img.shields.io/badge/Swift-5.3+-F05138.svg?style=flat-square)](https://swift.org) [![Swift Package Manager](https://img.shields.io/badge/spm-compatible-F05138.svg?style=flat-square)](https://swift.org/package-manager) [![Build Status](https://img.shields.io/github/workflow/status/b9swift/Action/Swift?style=flat-square&colorA=555555&colorB=F05138)](https://github.com/b9swift/AssociatedObject/actions) [![gitee 镜像](https://img.shields.io/badge/%E9%95%9C%E5%83%8F-gitee-C61E22.svg?style=flat-square)](https://gitee.com/b9swift/AssociatedObject) [![GitHub Source](https://img.shields.io/badge/Source-GitHub-24292F.svg?style=flat-square)](https://github.com/b9swift/AssociatedObject) 方便地在 Swift 中利用 Objective-C 关联对象。 ## 集成 使用 Swift Package Manager 或手工导入。 You can also use [GitHub source](https://github.com/b9swift/AssociatedObject). ## 使用 定义扩展属性可以像下面这样,不仅支持 Objective-C 对象,各种 Swift 类型也支持。 ```swift import B9AssociatedObject private let fooAssociation = AssociatedObject() extension SomeObject { var foo: String? { get { fooAssociation[self] } set { fooAssociation[self] = newValue } } } ```