Skip to content

Commit c36a1cb

Browse files
committed
feat: use gyb plugin, finish userdefault with test cases
1 parent 87ac0f9 commit c36a1cb

20 files changed

+861
-23
lines changed

.github/CODEOWNERS

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Lines starting with '#' are comments.
2+
# Each line is a case-sensitive file pattern followed by one or more owners.
3+
# Order is important. The last matching pattern has the most precedence.
4+
# More information: https://docs.github.com/en/articles/about-code-owners
5+
#
6+
# Please mirror the repository's file hierarchy in case-sensitive lexicographic
7+
# order.
8+
9+
# TODO: /.clang-format
10+
# TODO: /.gitattributes
11+
12+
# .github
13+
/.github @showxu
14+
/.github/CODEOWNERS @showxu
15+
/.github/ISSUE_TEMPLATE/ @showxu
16+
/.github/PULL_REQUEST_TEMPLATE.md @showxu
17+
18+
# TODO: /.gitignore
19+
# TODO: /CODE_OF_CONDUCT.md
20+
# TODO: /CODE_OWNERS.TXT
21+
# TODO: /CONTRIBUTING.md
22+
# TODO: /LICENSE.txt
23+
# TODO: /README.md
24+
25+
# Sources
26+
/Sources @showxu
27+
28+
# Tests
29+
/Tests @showxu
30+
31+
# Plugins
32+
/Plugins @showxu

.github/ISSUE_TEMPLATE/BUG_REPORT.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
name: Bug report
3+
about: Something isn't working as expected, create a report to help us improve.
4+
title: ''
5+
labels: bug, triage needed
6+
assignees: ''
7+
---
8+
9+
<!--
10+
Thanks for contributing to the Swift UserDefault!
11+
12+
Before you submit your issue, please replace each paragraph
13+
below with the relevant details for your bug, and complete
14+
the steps in the checklist by placing an 'x' in each box:
15+
16+
- [x] I've completed this task
17+
- [ ] This task isn't completed
18+
-->
19+
20+
Replace this paragraph with a short description of the incorrect incorrect behavior. If this is a regression, please note the last version that the behavior was correct in addition to your current version.
21+
22+
### Description
23+
<!-- Describe clearly and concisely what the bug is. -->
24+
25+
### Checklist
26+
- [ ] If possible, I've reproduced the issue using the `main` branch of this package
27+
- [ ] I've searched for [existing GitHub issues](https://github.com/swift-library/swift-userdefault/issues)
28+
29+
### Steps to Reproduce
30+
<!--
31+
Explain how to reproduce the problem (in steps if seen fit) and include either
32+
an inline test case (preferred) or a project that reproduces it. Consider
33+
reducing the sample to the smallest amount of code possible — a smaller test
34+
case is easier to reason about and more appealing to сontributors.
35+
-->
36+
37+
Replace this paragraph with an explanation of how to reproduce the incorrect behavior. This could include a code listing for a reduced version of your command, or a link to the code that is exhibiting the issue.
38+
39+
### Expected behavior
40+
<!-- Describe what you expected to happen. -->
41+
42+
<!-- If deemed helpful, add screenshots that showcase the problem. -->
43+
<!-- **Screenshots** -->
44+
45+
<!--
46+
Include information about the Swift compiler version and, if applicable, the
47+
Xcode version you are observing the problem in and the deployment target.
48+
-->
49+
50+
### Actual behavior
51+
Describe or copy/paste the behavior you observe.
52+
53+
### Environment
54+
- Swift compiler version info <!-- replace with the output of 'swiftc -version' -->
55+
- Xcode version info <!-- replace with the output of 'xcodebuild -version' -->
56+
- Deployment target: <!-- e.g. iOS 12.3 -->
57+
- **Swift UserDefault version:** `0.0.1` or the `main` branch, for example.
58+
59+
<!-- Add any other context about the problem as appropriate. -->
60+
<!-- **Additional context** -->
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
name: Feature Request
3+
about: A suggestion for a new feature
4+
title: ''
5+
labels: feature, triage needed
6+
assignees: ''
7+
---
8+
9+
<!--
10+
Thanks for contributing to the Swift UserDefault!
11+
12+
Before you submit your issue, please replace the paragraph
13+
below with information about your proposed feature.
14+
15+
If you haven't found or started a thread on the Swift UserDefault yet, consider
16+
socializing your idea in the "Discussion"
17+
(https://github.com/orgs/swift-library/discussions) after submitting this request.
18+
While GitHub issues do great for tracking
19+
purposes, the forums are far better ground for drawing attention to ideas and
20+
gauging interest from the community.
21+
22+
-->
23+
24+
Replace this paragraph with a description of your proposed feature. Code samples that show what's missing, or what new capabilities will be possible, are very helpful! Provide links to existing issues or external references/discussions, if appropriate.
25+
26+
### Motivation
27+
<!-- Describe the problem that your feature seeks to address. -->
28+
29+
### Solution
30+
<!--
31+
Describe your solution to the problem. Provide examples and describe how
32+
they work.
33+
-->
34+
35+
### Alternatives considered
36+
<!--
37+
Describe any alternative approaches or features that you have considered in
38+
addressing the problem, and why you chose this approach instead.
39+
-->
40+
41+
<!--
42+
Add any other context about your feature as appropriate. For example, link out
43+
to a discussion on the Swift forums (https://forums.swift.org).
44+
-->
45+
<!-- **Additional context** -->

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
blank_issues_enabled: false
2+
contact_links:
3+
- name: Discussion
4+
url: https://github.com/orgs/swift-library/discussions
5+
about: Questions about using Swift UserDefault? Ask here!

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!--
2+
Thanks for contributing to the Swift UserDefault!
3+
4+
If this pull request adds new API, please add '?template=new.md'
5+
to the URL to switch to the appropriate template.
6+
7+
Before you submit your request, please replace the paragraph
8+
below with the relevant details, and complete the steps in the
9+
checklist by placing an 'x' in each box:
10+
11+
- [x] I've completed this task
12+
- [ ] This task isn't completed
13+
-->
14+
15+
<!-- What's in this pull request? -->
16+
Replace this paragraph with a description of your changes and rationale. Provide links to an existing issue or external references/discussions, if appropriate.
17+
18+
<!--
19+
If this pull request resolves any GitHub issues, link them.
20+
For information about linking a pull request to an issue, see:
21+
https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
22+
-->
23+
Resolves #NNNNN, fix swift-library/swift-userdefault#MMMMM.
24+
25+
### Checklist
26+
- [ ] I've added at least one test that validates that my change is working, if appropriate
27+
- [ ] I've followed the code style of the rest of the project
28+
- [ ] I've read the [Contribution Guidelines](https://github.com/swift-library/swift-userdefault/blob/main/CONTRIBUTING.md)
29+
- [ ] I've updated the documentation if necessary

.github/PULL_REQUEST_TEMPLATE/NEW.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!--
2+
Thanks for contributing to the Swift UserDefault!
3+
4+
Before you submit your request, please replace each paragraph
5+
below with the relevant details, and complete the steps in the
6+
checklist by placing an 'x' in each box:
7+
8+
- [x] I've completed this task
9+
- [ ] This task isn't completed
10+
-->
11+
12+
### Description
13+
Replace this paragraph with a description of your changes and rationale. Provide links to an existing issue or external references/discussions, if appropriate.
14+
15+
### Detailed Design
16+
Include any additional information about the design here. At minimum, show any new API:
17+
18+
```swift
19+
/// The new feature implemented by this pull request.
20+
struct NewFeature {}
21+
```
22+
23+
### Documentation Plan
24+
How has the new feature been documented? Have the relevant portions of the guide been updated in addition to symbol-level documentation?
25+
26+
### Test Plan
27+
How is the new feature tested?
28+
29+
### Source Impact
30+
What is the impact of this change on existing users? Does it deprecate or remove any existing API?
31+
32+
### Checklist
33+
- [ ] I've added at least one test that validates that my change is working, if appropriate
34+
- [ ] I've followed the code style of the rest of the project
35+
- [ ] I've read the [Contribution Guidelines](https://github.com/swift-library/swift-userdefault/blob/main/CONTRIBUTING.md)
36+
- [ ] I've updated the documentation if necessary

.spi.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version: 1
2+
builder:
3+
configs:
4+
- documentation_targets: [UserDefault, UserDefaultUtils]

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# CHANGELOG
2+
3+
<!--
4+
Add new items at the end of the relevant section under **Unreleased**.
5+
-->
6+
7+
## [Unreleased]
8+
9+
*No changes yet.*
10+
11+
---
12+
13+
## [0.0.1] - 2023-05-02
14+
15+
- `UserDefault` initial release.
16+
17+
<!-- Link references for releases -->
18+
19+
[Unreleased]: https://github.com/swift-library/swift-userdefault/compare/0.0.1...HEAD
20+
[0.0.2]: https://github.com/swift-library/swift-userdefault/compare/0.0.1...0.0.2
21+
[0.0.1]: https://github.com/swift-library/swift-userdefault/releases/tag/0.0.1

Package.resolved

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"object": {
3+
"pins": [
4+
{
5+
"package": "swift-gyb",
6+
"repositoryURL": "https://github.com/swift-library/swift-gyb",
7+
"state": {
8+
"branch": null,
9+
"revision": "f76833ee01a7f9c8cf0dd0a7e2ddb7083bdc28dd",
10+
"version": "0.0.1"
11+
}
12+
}
13+
]
14+
},
15+
"version": 1
16+
}

Package.swift

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,46 @@
1-
// swift-tools-version: 5.8
1+
// swift-tools-version: 5.5
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
7-
name: "swift-package-template",
7+
name: "swift-userdefault",
8+
platforms: [.macOS(.v10_13), .iOS(.v11), .tvOS(.v11), .watchOS(.v4)],
89
products: [
910
// Products define the executables and libraries a package produces, making them visible to other packages.
1011
.library(
11-
name: "swift-package-template",
12-
targets: ["swift-package-template"]),
12+
name: "UserDefault",
13+
targets: [
14+
"UserDefault",
15+
"UserDefaultUtils",
16+
]),
17+
18+
.library(
19+
name: "DynamicUserDefault",
20+
type: .dynamic,
21+
targets: [
22+
"UserDefault",
23+
"UserDefaultUtils",
24+
]),
25+
],
26+
dependencies: [
27+
.package(url: "https://github.com/swift-library/swift-gyb", from: "0.0.1"),
1328
],
1429
targets: [
1530
// Targets are the basic building blocks of a package, defining a module or a test suite.
1631
// Targets can depend on other targets in this package and products from dependencies.
1732
.target(
18-
name: "swift-package-template"),
33+
name: "UserDefaultUtils", dependencies: ["UserDefault"]),
34+
35+
.target(
36+
name: "UserDefault",
37+
plugins: [.plugin(name: "Gyb", package: "swift-gyb")]),
38+
1939
.testTarget(
20-
name: "swift-package-templateTests",
21-
dependencies: ["swift-package-template"]),
40+
name: "UserDefaultTests",
41+
dependencies: [
42+
"UserDefault",
43+
"UserDefaultUtils"
44+
]),
2245
]
2346
)

README.md

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,70 @@
1-
# Swift Package Template
1+
# Swift UserDefault
22

3-
The package template for swift library.
3+
The property wrapper implementation for `Foundation.UserDefaults`.
4+
5+
## Usage
6+
7+
**Code Example**
8+
9+
```swift
10+
class Settings {
11+
public enum Keys: String, CaseIterable {
12+
case model
13+
case version
14+
case safetyCheckerDisclaimer
15+
case computeUnits
16+
}
17+
18+
@UserDefault(key: Keys.model, userDefaults: .standard)
19+
public var currentModel: ModelInfo! = nil
20+
21+
@UserDefault(key: Keys.version, userDefaults: .standard)
22+
public var version: Int = 0
23+
24+
@UserDefault(key: Keys.safetyCheckerDisclaimer)
25+
public var safetyCheckerDisclaimerRead = false
26+
27+
@UserDefault(key: Keys.computeUnits)
28+
public var systemComputeUnits: ComputeUnits? = .cpuOnly
29+
}
30+
```
31+
32+
## Adding `swift-userdefault` as a Dependency
33+
34+
To use the `swift-userdefault` library in a SwiftPM project,
35+
add it to the dependencies for your package and your target:
36+
37+
```swift
38+
let package = Package(
39+
// name, platforms, products, etc.
40+
dependencies: [
41+
// other dependencies
42+
.package(url: "https://github.com/swift-library/swift-userdefault", from: "0.0.1"),
43+
],
44+
targets: [
45+
.executableTarget(
46+
name: "<command-line-tool>",
47+
dependencies: [
48+
// other dependencies
49+
.product(name: "UserDefault", package: "swift-userdefault"),
50+
],
51+
plugins: [
52+
// other dependencies
53+
]
54+
),
55+
// other targets
56+
]
57+
)
58+
```
59+
60+
### Supported Versions
61+
62+
The most recent versions of swift-userdefault support Swift 5.8 and newer. The minimum Swift version supported by swift-userdefault releases are detailed below:
63+
64+
swift-userdefault | Minimum Swift Version
65+
----------|----------------------
66+
`0.0.1` | 5.8
67+
68+
<!-- Link references for readme -->
69+
70+
[swift]: https://github.com/apple/swift

0 commit comments

Comments
 (0)