Skip to content

Commit 4cbdf67

Browse files
committed
Add support for strict concurrency and tweak some styles
1 parent ba00230 commit 4cbdf67

File tree

11 files changed

+195
-214
lines changed

11 files changed

+195
-214
lines changed

Package.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@ let package = Package(
1414
products: [
1515
.library(
1616
name: "TagKit",
17-
targets: ["TagKit"]),
17+
targets: ["TagKit"]
18+
)
1819
],
19-
dependencies: [],
2020
targets: [
2121
.target(
2222
name: "TagKit",
23-
dependencies: []),
23+
swiftSettings: [
24+
.enableExperimentalFeature("StrictConcurrency")
25+
]
26+
),
2427
.testTarget(
2528
name: "TagKitTests",
26-
dependencies: ["TagKit"]),
29+
dependencies: ["TagKit"]
30+
)
2731
]
2832
)

RELEASE_NOTES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
TagKit will use semver after 1.0.
44

55

6+
## 0.3
7+
8+
This version adds support for strict concurrency.
9+
10+
This requires standard styles to be converted to read-only values.
11+
12+
This version also adjusts the visual appearance of some standard styles.
13+
14+
15+
616
## 0.2
717

818
This version bumps the package to Swift 5.9 and adds support for visionOS.

Sources/TagKit/SlugConfiguration.swift

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,19 @@
88

99
import Foundation
1010

11-
/**
12-
This configuration defines how ``Slugifiable`` types are to
13-
be slugified.
14-
15-
Use the ``SlugConfiguration/standard`` configuration if you
16-
want the standard configuration, which limits the slugified
17-
strings to `a-z` and `1-9`, using `-` as separator.
18-
*/
11+
/// This configuration defines how ``Slugifiable`` types are
12+
/// slugified.
13+
///
14+
/// Use the ``SlugConfiguration/standard`` configuration for
15+
/// the default behavior, which limits the slugified strings
16+
/// to `a-z` and `1-9`, using `-` as separator.
1917
public struct SlugConfiguration {
2018

21-
/**
22-
Create a new slug configurator.
23-
24-
- Parameters:
25-
- separator: The separator to use in the slugified string, by default `-`.
26-
- allowedCharacters: The characters to allow in the slugified string, by default alphanumerical characters and `-`.
27-
*/
19+
/// Create a new slug configurator.
20+
///
21+
/// - Parameters:
22+
/// - separator: The separator to use in the slugified string, by default `-`.
23+
/// - allowedCharacters: The characters to allow in the slugified string, by default alphanumerical characters and `-`.
2824
public init(
2925
separator: String = "-",
3026
allowedCharacters: String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
@@ -35,27 +31,19 @@ public struct SlugConfiguration {
3531
self.allowedCharacterSet = NSCharacterSet(charactersIn: chars)
3632
}
3733

38-
/**
39-
The separator to use in the slugified string.
40-
*/
34+
/// The separator to use in the slugified string.
4135
public let separator: String
4236

43-
/**
44-
The characters to allow in the slugified string.
45-
*/
37+
/// The characters to allow in the slugified string.
4638
public let allowedCharacters: String
4739

48-
/**
49-
The character set to allow in the slugified string.
50-
*/
40+
/// The character set to allow in the slugified string.
5141
public let allowedCharacterSet: NSCharacterSet
5242
}
5343

5444
public extension SlugConfiguration {
5545

56-
/**
57-
Create a standard slug configuration, which allows `a-z`
58-
and `1-9` and uses `-` as separator.
59-
*/
60-
static let standard = SlugConfiguration()
46+
/// A standard slug configuration, that allows `a-z` and
47+
/// `1-9` and uses `-` as the component separator.
48+
static var standard: SlugConfiguration { .init() }
6149
}

Sources/TagKit/Slugifiable.swift

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,32 @@
88

99
import Foundation
1010

11-
/**
12-
This protocol describes a type that can be slugified into a
13-
slug representation that can be used in e.g. tags.
14-
15-
Types that implement this protocol get access to a bunch of
16-
additional functionality, e.g. ``slugified(configuration:)``.
17-
18-
When slugifying, "Hello there, friends!" will by default be
19-
converted to `hello-there-friends`, but this format depends
20-
on the ``SlugConfiguration`` that is used.
21-
22-
This protocol is automatically implemented by `String`.
23-
*/
11+
/// This protocol describes a slugifiable type, which can be
12+
/// represented as a slugified string.
13+
///
14+
/// Slugified strings are for instance used in urls and tags,
15+
/// where a text is represented by removing unsupported text
16+
/// components. The standard format can be customized with a
17+
/// custom ``SlugConfiguration``.
18+
///
19+
/// By default, `Hello, world!` is slugified to `hello-world`.
20+
///
21+
/// This protocol is automatically implemented by `String`.
2422
public protocol Slugifiable {
2523

26-
/**
27-
The slugifiable value that will be used when creating a
28-
slugified string.
29-
*/
24+
/// The value used to create a slugified representation.
3025
var slugifiableValue: String { get }
3126
}
3227

3328
public extension Slugifiable {
3429

35-
/**
36-
Convert the slugifiable value to a slugified string.
37-
38-
With the default configuration, `I'd love an AppleCar!`
39-
will be slugified as `i-d-love-an-apple-car`.
40-
41-
- Parameters:
42-
- configuration: The configuration to use, by default ``SlugConfiguration/standard``.
43-
*/
30+
/// Convert the slugifiable value to a slugified string.
31+
///
32+
/// With the default configuration, `Hello, world!` will
33+
/// be slugified to `hello-world`.
34+
///
35+
/// - Parameters:
36+
/// - configuration: The configuration to use, by default ``SlugConfiguration/standard``.
4437
func slugified(
4538
configuration: SlugConfiguration = .standard
4639
) -> String {
@@ -55,9 +48,5 @@ public extension Slugifiable {
5548

5649
extension String: Slugifiable {
5750

58-
/**
59-
The sluggable value that will be used when creating the
60-
slugified result.
61-
*/
6251
public var slugifiableValue: String { self }
6352
}

Sources/TagKit/Taggable+Collection.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,15 @@ import Foundation
1010

1111
public extension Collection where Element: Taggable {
1212

13-
/**
14-
Get all the slugified tags in the collection.
15-
16-
The tags are slugified to remove any casing and spacing
17-
differences that may exist between the items.
18-
*/
13+
/// Get all the slugified tags in the collection.
14+
///
15+
/// Read more about slugified strings in ``Slugifiable``.
1916
var allTags: [String] {
2017
let slugs = flatMap { $0.slugifiedTags }
2118
return Array(Set(slugs)).sorted()
2219
}
2320

24-
/**
25-
Get all items in the collection that have a certain tag.
26-
*/
21+
/// Get all items in the collection with a certain tag.
2722
func withTag(_ tag: String) -> [Element] {
2823
filter { $0.hasTag(tag) }
2924
}

Sources/TagKit/Taggable.swift

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,81 +8,62 @@
88

99
import Foundation
1010

11-
/**
12-
This protocol describe types that can be tagged with one or
13-
many tags, which can then be used to group, search etc.
14-
15-
Types that implement this protocol get access to a bunch of
16-
additional functionality, e.g. ``hasTags``, ``addTag(_:)``.
17-
18-
Note that the ``tags`` property is a raw list of tags, that
19-
should contain slugified tags. However, since this protocol
20-
can be implemented by any type, you can use ``slugifiedTags``
21-
to ensure that you get a list of slugified tags.
22-
*/
11+
/// This protocol describe types that can be tagged with one
12+
/// or many tags, which can be used to group, search etc.
13+
///
14+
/// Types that implement this protocol get access to a bunch
15+
/// of additional features, e.g. ``hasTags``, ``addTag(_:)``,
16+
/// ``toggleTag(_:)``, etc.
17+
///
18+
/// Note that the ``tags`` property is a raw string list. If
19+
/// ypu want a list of slugified tags, use ``slugifiedTags``.
2320
public protocol Taggable {
2421

25-
/**
26-
All tags that have been applied to the item.
27-
*/
22+
/// All tags that have been applied to the item.
2823
var tags: [String] { get set }
2924
}
3025

3126
public extension Taggable {
3227

33-
/**
34-
Whether or not the item has any tags.
35-
*/
28+
/// Whether or not the item has any tags.
3629
var hasTags: Bool {
3730
!tags.isEmpty
3831
}
3932

40-
/**
41-
Get a list of slugified ``tags``.
42-
*/
33+
/// Get a list of slugified ``tags``.
4334
var slugifiedTags: [String] {
4435
slugifiedTags()
4536
}
4637

47-
/**
48-
Add a tag to the taggable type.
49-
*/
38+
/// Add a tag to the taggable type.
5039
mutating func addTag(_ tag: String) {
5140
if hasTag(tag) { return }
5241
tags.append(tag)
5342
}
5443

55-
/**
56-
Whether or not the item has a certain tag.
57-
*/
44+
/// Whether or not the item has a certain tag.
5845
func hasTag(_ tag: String) -> Bool {
5946
if tag.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { return true }
6047
return slugifiedTags.contains(tag.slugified())
6148
}
6249

63-
/**
64-
Remove a tag from the taggable type.
65-
*/
50+
/// Remove a tag from the taggable type.
6651
mutating func removeTag(_ tag: String) {
6752
guard hasTag(tag) else { return }
6853
tags = tags.filter { $0 != tag }
6954
}
7055

71-
/**
72-
Get a list of slugified ``tags`` for a certain config.
73-
74-
- Parameters:
75-
- config: The slug configuration to use, by default ``SlugConfiguration/standard``.
76-
*/
56+
/// Get a list of slugified ``tags``.
57+
///
58+
/// - Parameters:
59+
/// - config: The slug configuration to use, by default ``SlugConfiguration/standard``.
7760
func slugifiedTags(
7861
configuration: SlugConfiguration = .standard
7962
) -> [String] {
8063
tags.map { $0.slugified(configuration: configuration) }
8164
}
8265

83-
/**
84-
Toggle a tag on the taggable type.
85-
*/
66+
/// Toggle a tag on the taggable type.
8667
mutating func toggleTag(_ tag: String) {
8768
if hasTag(tag) {
8869
removeTag(tag)

Sources/TagKit/Views/FlowLayout.swift

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,14 @@
1010

1111
import SwiftUI
1212

13-
/**
14-
This view lists data in a leading to trailing flow.
15-
16-
The view will break to a new line whenever the view doesn't
17-
fit on the current line.
18-
19-
You must specify a container type, since the view has to be
20-
rendered differently depending on if it's in a `ScrollView`
21-
or a `VerticalStack`.
22-
23-
The view is internal and kept for reference, if we will use
24-
it on other ways in the future.
25-
*/
13+
/// This view lists data in a leading to trailing flow.
14+
///
15+
/// The view will break to a new line whenever the view does
16+
/// not fit on the current line.
17+
///
18+
/// You must specify a container type, since the view has to
19+
/// be rendered differently depending on in the container it
20+
/// is used in, e.g. `ScrollView`, `VStack`, etc.
2621
public struct FlowLayout<ItemType, ItemView: View>: View {
2722

2823
/// Create a flow layout.
@@ -75,6 +70,7 @@ public struct FlowLayout<ItemType, ItemView: View>: View {
7570
}
7671
}
7772

73+
@MainActor
7874
private extension FlowLayout {
7975

8076
var content: some View {

0 commit comments

Comments
 (0)