Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

README

        

## Extension Property


platforms

Swift4.1


License




Carthage


SwiftPM


Version

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.