Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jrsaruo/propertyaccessor
An accessor macro that adds the getter and the setter to the property.
https://github.com/jrsaruo/propertyaccessor
Last synced: about 1 month ago
JSON representation
An accessor macro that adds the getter and the setter to the property.
- Host: GitHub
- URL: https://github.com/jrsaruo/propertyaccessor
- Owner: jrsaruo
- License: mit
- Created: 2023-09-24T09:03:54.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-24T10:13:07.000Z (over 1 year ago)
- Last Synced: 2023-09-24T17:13:57.168Z (over 1 year ago)
- Language: Swift
- Size: 15.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PropertyAccessor
An accessor macro that adds the getter and the setter to the property.
## Requirements
- iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+
- Xcode 15+
- Swift 5.9+## Usage
```swift
final class CustomView: UIView {
private let titleLabel = UILabel()@Accessor(to: \Self.titleLabel.text)
var title: String?/*
Expanded to:
var title: String? {
get {
self[keyPath: \Self.titleLabel.text]
}
set {
self[keyPath: \Self.titleLabel.text] = newValue
}
}
*/
}
```## Using PropertyAccessor in your project
To use the `PropertyAccessor` library in a SwiftPM project, add the following line to the dependencies in your `Package.swift` file:
```swift
.package(url: "https://github.com/jrsaruo/PropertyAccessor", from: "1.0.0"),
```and add `PropertyAccessor` as a dependency for your target:
```swift
.target(name: "", dependencies: [
.product(name: "PropertyAccessor", package: "PropertyAccessor"),
// other dependencies
]),
```Finally, add `import PropertyAccessor` in your source code.
> [!NOTE]
> You may see an alert that says “'PropertyAccessorMacros' must be enabled before it can be used. Enable it now?” so you will have to trust and enable it.