Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cats-oss/extensionproperty
🗜The utility interface for Associated Object
https://github.com/cats-oss/extensionproperty
carthage cocoapods extension protocol-oriented swift swift-package-manager
Last synced: 3 months ago
JSON representation
🗜The utility interface for Associated Object
- Host: GitHub
- URL: https://github.com/cats-oss/extensionproperty
- Owner: cats-oss
- License: mit
- Created: 2018-07-10T01:21:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-11T02:11:19.000Z (over 6 years ago)
- Last Synced: 2024-10-30T17:13:47.826Z (3 months ago)
- Topics: carthage, cocoapods, extension, protocol-oriented, swift, swift-package-manager
- Language: Swift
- Homepage:
- Size: 54.7 KB
- Stars: 8
- Watchers: 21
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Extension Property
The utility interface for **Associated Object**.
If you use this, you can attach any variables in extension.## Usage
```swift
protocol Animal {}enum AnimalPropertyKeys: String, ExtensionPropertyKey {
case name
}final class Dog: Animal {}
extension Dog: ExtensionProperty {}
// Declare setter and getter to property
extension Animal where Self: ExtensionProperty {
var name: String {
get {
return getProperty(key: AnimalPropertyKeys.name, defaultValue: "")
}set {
setProperty(key: AnimalPropertyKeys.name, newValue: newValue)
}
}
}let dog = Dog()
// You can assign string to dog.name
dog.name = "Autumn"
```Please check out and try the unit test.
## Installation
### Carthage
If you’re using [Carthage](https://github.com/Carthage/Carthage), simply add ExtensionProperty to your `Cartfile`:
```
github "cats-oss/ExtensionProperty"
```### CocoaPods
ExtensionProperty is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'ExtensionProperty'
```### Swift Package Manager
If you’re using [Swift Package Manager](https://github.com/apple/swift-package-manager), simply add ExtensionProperty to your `Package.swift`:
```swift
dependencies: [
.package(url: "https://github.com/cats-oss/ExtensionProperty", from: "1.0.2")
]
```## Requirements
* Xcode 9.3
* Swift 4.1 or greater## LICENSE
ExtensionProperty is available under the MIT license. See the [LICENSE file](./LICENSE) for more info.