Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/juniperphoton/photonmacros
https://github.com/juniperphoton/photonmacros
Last synced: 26 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/juniperphoton/photonmacros
- Owner: JuniperPhoton
- Created: 2023-10-09T07:18:04.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-24T14:07:14.000Z (11 months ago)
- Last Synced: 2024-02-25T14:45:40.667Z (11 months ago)
- Language: Swift
- Size: 20.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PhotonMacros
Provides some useful macros to use in iOS/macOS development.
## UserDefaultsAccess
This is an attached macro to generate the get/set access to the provided user default. Currently supports types of `Bool`, `Integer` and `String`.
The signature of this macro is:
```swift
public macro UserDefaultsAccess(defaultValue: T, key: String? = nil, store: UserDefaults = UserDefaults.standard)
```There are 3 parameters you should provide:
- `defaultValue`: If the specified key doesn't exist in the `UserDefaults`, the default value will be returned in the get method.
- `key`: The key string to access the `UserDefaults`. This can be nil if the key value is the same as the property name.
- `store`: The instance of `UserDefaults`. The default value is `.standard`.Usage:
```swift
@UserDefaultsAccess(defaultValue: false, store: AppSettings.getSharedUserDefault())
var sortByAscending: Bool
```This expansion of the code above is:
```swift
var sortByAscending: Bool {
get {
if AppSettings.getSharedUserDefault().value(forKey: "sortByAscending") == nil {
return false
}
return AppSettings.getSharedUserDefault().bool(forKey: "sortByAscending")
}
set {
AppSettings.getSharedUserDefault().setValue(newValue, forKey: "sortByAscending")
}
}
```# MIT License
Copyright (c) [2023] [JuniperPhoton]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.