Skip to content

Commit 333efa8

Browse files
Merge pull request #8 from SwiftPackageIndex/update-docs
Better documentation overview page
2 parents a1de1ca + 5933d73 commit 333efa8

File tree

3 files changed

+82
-69
lines changed

3 files changed

+82
-69
lines changed

Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ let package = Package(
2525
],
2626
dependencies: [],
2727
targets: [
28-
.target(name: "SemanticVersion", dependencies: []),
28+
.target(name: "SemanticVersion",
29+
dependencies: [],
30+
resources: [.process("Documentation.docc")]),
2931
.testTarget(name: "SemanticVersionTests", dependencies: ["SemanticVersion"]),
3032
]
3133
)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# ``SemanticVersion``
2+
3+
`SemanticVersion` is a struct representing a software or project version according to "Semantic Versioning".
4+
5+
Given a version number MAJOR.MINOR.PATCH, increment the:
6+
1. MAJOR version when you make incompatible API changes,
7+
2. MINOR version when you add functionality in a backwards compatible manner, and
8+
PATCH version when you make backwards compatible bug fixes.
9+
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
10+
11+
Find out more about [Semantic Versioning](https://semver.org).
12+
13+
Once instantiated, you can query a `SemanticVersion` about its components:
14+
15+
```swift
16+
let v123 = SemanticVersion(1, 2, 3)
17+
v123.isStable // true
18+
v123.isPreRelease // false
19+
v123.isMajorRelease // false
20+
v123.isMinorRelease // false
21+
v123.isPatchRelease // true
22+
```
23+
24+
You can also instantiate a `SemanticVersion` from a string
25+
26+
```swift
27+
let v200 = SemanticVersion("2.0.0")!
28+
v200.isStable // true
29+
v200.isPreRelease // false
30+
v200.isMajorRelease // true
31+
v200.isMinorRelease // false
32+
v200.isPatchRelease // false
33+
```
34+
35+
`SemanticVersion` supports beta versions:
36+
37+
```swift
38+
let v300rc1 = SemanticVersion("3.0.0-rc1-test")!
39+
v300rc1.isStable // false
40+
v300rc1.isPreRelease // true
41+
v300rc1.isMajorRelease // false
42+
v300rc1.isMinorRelease // false
43+
v300rc1.isPatchRelease // false
44+
v300rc1.major // 3
45+
v300rc1.minor // 0
46+
v300rc1.patch // 0
47+
v300rc1.preRelease // "rc1-test"
48+
```
49+
50+
`SemanticVersion` is `Comparable` and `Equatable`:
51+
52+
```swift
53+
v123 < v200 // true
54+
SemanticVersion("2.0.0")! < SemanticVersion("2.0.1")! // true
55+
// NB: beta versions come before their releases
56+
SemanticVersion("2.0.0")! > SemanticVersion("2.0.0-b1")! // true
57+
v123 == SemanticVersion("1.2.3") // true
58+
SemanticVersion("v1.2.3-beta1+build5")
59+
== SemanticVersion(1, 2, 3, "beta1", "build5") // true
60+
```
61+
62+
`SemanticVersion` is `Hashable`:
63+
64+
```swift
65+
let dict = [ // [{major 3, minor 0, patch 0,...
66+
v123: 1,
67+
v200: 2,
68+
v300rc1: 3
69+
]
70+
```
71+
72+
`SemanticVersion` is `Codable`:
73+
74+
```swift
75+
let data = try JSONEncoder().encode(v123) // 58 bytes
76+
let decoded = try JSONDecoder().decode(SemanticVersion.self, from: data) // 1.2.3
77+
decoded == v123 // true
78+
```
79+

Sources/SemanticVersion/SemanticVersion.swift

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -22,74 +22,6 @@ import Foundation
2222
/// 2. MINOR version when you add functionality in a backwards compatible manner, and
2323
/// PATCH version when you make backwards compatible bug fixes.
2424
/// Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
25-
///
26-
/// Once instantiated, you can query a `SemanticVersion` about its components:
27-
///
28-
/// ```swift
29-
/// let v123 = SemanticVersion(1, 2, 3)
30-
/// v123.isStable // true
31-
/// v123.isPreRelease // false
32-
/// v123.isMajorRelease // false
33-
/// v123.isMinorRelease // false
34-
/// v123.isPatchRelease // true
35-
/// ```
36-
///
37-
/// You can also instantiate a `SemanticVersion` from a string
38-
///
39-
/// ```swift
40-
/// let v200 = SemanticVersion("2.0.0")!
41-
/// v200.isStable // true
42-
/// v200.isPreRelease // false
43-
/// v200.isMajorRelease // true
44-
/// v200.isMinorRelease // false
45-
/// v200.isPatchRelease // false
46-
/// ```
47-
///
48-
/// `SemanticVersion` supports beta versions:
49-
///
50-
/// ```swift
51-
/// let v300rc1 = SemanticVersion("3.0.0-rc1-test")!
52-
/// v300rc1.isStable // false
53-
/// v300rc1.isPreRelease // true
54-
/// v300rc1.isMajorRelease // false
55-
/// v300rc1.isMinorRelease // false
56-
/// v300rc1.isPatchRelease // false
57-
/// v300rc1.major // 3
58-
/// v300rc1.minor // 0
59-
/// v300rc1.patch // 0
60-
/// v300rc1.preRelease // "rc1-test"
61-
/// ```
62-
///
63-
/// `SemanticVersion` is `Comparable` and `Equatable`:
64-
///
65-
/// ```swift
66-
/// v123 < v200 // true
67-
/// SemanticVersion("2.0.0")! < SemanticVersion("2.0.1")! // true
68-
/// // NB: beta versions come before their releases
69-
/// SemanticVersion("2.0.0")! > SemanticVersion("2.0.0-b1")! // true
70-
/// v123 == SemanticVersion("1.2.3") // true
71-
/// SemanticVersion("v1.2.3-beta1+build5")
72-
/// == SemanticVersion(1, 2, 3, "beta1", "build5") // true
73-
/// ```
74-
///
75-
/// `SemanticVersion` is `Hashable`:
76-
///
77-
/// ```swift
78-
/// let dict = [ // [{major 3, minor 0, patch 0,...
79-
/// v123: 1,
80-
/// v200: 2,
81-
/// v300rc1: 3
82-
/// ]
83-
/// ```
84-
///
85-
/// `SemanticVersion` is `Codable`:
86-
///
87-
/// ```swift
88-
/// let data = try JSONEncoder().encode(v123) // 58 bytes
89-
/// let decoded = try JSONDecoder().decode(SemanticVersion.self, from: data) // 1.2.3
90-
/// decoded == v123 // true
91-
/// ```
92-
9325
public struct SemanticVersion: Codable, Equatable, Hashable {
9426
public var major: Int
9527
public var minor: Int

0 commit comments

Comments
 (0)