Skip to content

Commit 500dd51

Browse files
Additional PR Checks (#4)
Apple Platform Checks; Swiftformat
1 parent 1c7c16c commit 500dd51

21 files changed

Lines changed: 263 additions & 206 deletions

.github/workflows/pull_request.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Pull Request
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
8+
env:
9+
SCHEME: "CodablePlus"
10+
11+
jobs:
12+
Lint:
13+
runs-on: macos-26
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v6
17+
- name: Lint
18+
run: swiftformat --lint . --reporter github-actions-log
19+
20+
Swift:
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
os: [
25+
macos-26,
26+
ubuntu-latest,
27+
]
28+
runs-on: ${{ matrix.os }}
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v6
32+
- name: Cache
33+
uses: actions/cache@v5
34+
with:
35+
path: |
36+
.build
37+
~/Library/Developer/Xcode/DerivedData/ModuleCache.noindex
38+
~/Library/Caches/org.swift.swiftpm
39+
~/Library/org.swift.swiftpm
40+
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.swift', '**/Package.resolved') }}
41+
restore-keys: |
42+
${{ runner.os }}-spm-
43+
- name: Package Resolution
44+
run: swift package resolve
45+
- name: Build
46+
run: swift build
47+
- name: Test
48+
run: swift test
49+
50+
Xcode:
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
platform: [
55+
"macOS",
56+
"iOS",
57+
"tvOS",
58+
"watchOS",
59+
"visionOS",
60+
"macOS,variant=Mac Catalyst",
61+
]
62+
runs-on: macos-26
63+
steps:
64+
- name: Checkout
65+
uses: actions/checkout@v6
66+
- name: Cache
67+
uses: actions/cache@v5
68+
with:
69+
path: |
70+
.build
71+
~/Library/Developer/Xcode/DerivedData/ModuleCache.noindex
72+
~/Library/Caches/org.swift.swiftpm
73+
~/Library/org.swift.swiftpm
74+
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.swift', '**/Package.resolved') }}
75+
restore-keys: |
76+
${{ runner.os }}-spm-
77+
- name: Package Resolution
78+
run: set -o pipefail && xcodebuild -resolvePackageDependencies | xcbeautify
79+
- name: Build
80+
env:
81+
DESTINATION: "generic/platform=${{ matrix.platform }}"
82+
run: set -o pipefail && xcodebuild build -scheme "$SCHEME" -destination "$DESTINATION" | xcbeautify

.github/workflows/swift.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

.swiftformat

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Compiler
2+
--languagemode 5
3+
--swiftversion 5.9
4+
5+
# Options
6+
--exclude derivedData
7+
--ifdef no-indent
8+
--indent 4
9+
10+
# Rules
11+
--disable blankLinesAtStartOfScope
12+
--disable hoistPatternLet
13+
--disable redundantType
14+
--disable unusedArguments
15+
--disable wrapArguments
16+
--disable wrapPropertyBodies

Package.swift

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

44
import PackageDescription
@@ -10,15 +10,16 @@ let package = Package(
1010
.macCatalyst(.v15),
1111
.iOS(.v15),
1212
.tvOS(.v15),
13-
.watchOS(.v8)
13+
.watchOS(.v8),
14+
.visionOS(.v1),
1415
],
1516
products: [
1617
.library(
1718
name: "CodablePlus",
1819
targets: ["CodablePlus"]),
1920
],
2021
dependencies: [
21-
22+
2223
],
2324
targets: [
2425
.target(

Sources/CodablePlus/AnyEncodable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/// A type-erased container that supports encoding its value to a `SingleValueEncodingContainer`.
22
public struct AnyEncodable: Encodable {
33
let value: Encodable
4-
4+
55
public init(_ value: Encodable) {
66
self.value = value
77
}
8-
8+
99
public func encode(to encoder: Encoder) throws {
1010
var container = encoder.singleValueContainer()
1111
try value.encode(to: &container)

Sources/CodablePlus/DictionaryKeys.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import Foundation
2020
public struct DictionaryKeys: CodingKey {
2121
public var stringValue: String
2222
public var intValue: Int?
23-
23+
2424
public init(stringValue: String) {
2525
self.stringValue = stringValue
2626
}
27-
27+
2828
public init(intValue: Int) {
29-
self.stringValue = "\(intValue)"
29+
stringValue = "\(intValue)"
3030
self.intValue = intValue
3131
}
3232
}

Sources/CodablePlus/KeyedDecodingContainerProtocol+Any.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public extension KeyedDecodingContainerProtocol {
1313
return doubleValue
1414
} else if let stringValue = try? decode(String.self, forKey: key) {
1515
return stringValue
16-
} else if let nestedDictionary = try? decode(Dictionary<String, Any>.self, forKey: key) {
16+
} else if let nestedDictionary = try? decode([String: Any].self, forKey: key) {
1717
return nestedDictionary
18-
} else if let nestedArray = try? decode(Array<Any>.self, forKey: key) {
18+
} else if let nestedArray = try? decode([Any].self, forKey: key) {
1919
return nestedArray
2020
} else if try decodeNil(forKey: key) {
2121
return NSNull()
@@ -24,15 +24,15 @@ public extension KeyedDecodingContainerProtocol {
2424
throw DecodingError.dataCorrupted(context)
2525
}
2626
}
27-
27+
2828
/// Decodes a value of any decodable type, if present.
2929
///
3030
/// - parameter key: The key that the decoded value is associated with.
3131
func decodeAnyIfPresent(forKey key: Key) throws -> Any? {
3232
guard contains(key) else {
3333
return nil
3434
}
35-
35+
3636
return try decodeAny(forKey: key)
3737
}
3838
}

Sources/CodablePlus/KeyedDecodingContainerProtocol+Containers.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public extension KeyedDecodingContainerProtocol {
1313
/// for the given key.
1414
/// - throws: `DecodingError.valueNotFound` if `self` has a null entry for
1515
/// the given key.
16-
func decode(_ type: Dictionary<String, Any>.Type, forKey key: Key) throws -> Dictionary<String, Any> {
17-
let container = try self.nestedContainer(keyedBy: DictionaryKeys.self, forKey: key)
16+
func decode(_ type: [String: Any].Type, forKey key: Key) throws -> [String: Any] {
17+
let container = try nestedContainer(keyedBy: DictionaryKeys.self, forKey: key)
1818
return try container.decode(type)
1919
}
2020

@@ -30,8 +30,8 @@ public extension KeyedDecodingContainerProtocol {
3030
/// for the given key.
3131
/// - throws: `DecodingError.valueNotFound` if `self` has a null entry for
3232
/// the given key.
33-
func decode(_ type: Array<Any>.Type, forKey key: Key) throws -> Array<Any> {
34-
var container = try self.nestedUnkeyedContainer(forKey: key)
33+
func decode(_ type: [Any].Type, forKey key: Key) throws -> [Any] {
34+
var container = try nestedUnkeyedContainer(forKey: key)
3535
return try container.decode(type)
3636
}
3737

@@ -48,7 +48,7 @@ public extension KeyedDecodingContainerProtocol {
4848
/// the value is a null value.
4949
/// - throws: `DecodingError.typeMismatch` if the encountered encoded value
5050
/// is not convertible to the requested type.
51-
func decodeIfPresent(_ type: Dictionary<String, Any>.Type, forKey key: Key) throws -> Dictionary<String, Any>? {
51+
func decodeIfPresent(_ type: [String: Any].Type, forKey key: Key) throws -> [String: Any]? {
5252
guard contains(key) else {
5353
return nil
5454
}
@@ -69,7 +69,7 @@ public extension KeyedDecodingContainerProtocol {
6969
/// the value is a null value.
7070
/// - throws: `DecodingError.typeMismatch` if the encountered encoded value
7171
/// is not convertible to the requested type.
72-
func decodeIfPresent(_ type: Array<Any>.Type, forKey key: Key) throws -> Array<Any>? {
72+
func decodeIfPresent(_ type: [Any].Type, forKey key: Key) throws -> [Any]? {
7373
guard contains(key) else {
7474
return nil
7575
}
@@ -86,36 +86,36 @@ public extension KeyedDecodingContainerProtocol where Key == DictionaryKeys {
8686
/// and convertible to the requested type.
8787
/// - throws: `DecodingError.typeMismatch` if the encountered encoded value
8888
/// is not convertible to the requested type.
89-
func decode(_ type: Dictionary<String, Any>.Type) throws -> Dictionary<String, Any> {
89+
func decode(_ type: [String: Any].Type) throws -> [String: Any] {
9090
var dictionary: [String: Any] = [:]
91-
91+
9292
for key in allKeys {
9393
if let boolValue = try? decode(Bool.self, forKey: key) {
9494
dictionary[key.stringValue] = boolValue
95-
95+
9696
} else if let intValue = try? decode(Int.self, forKey: key) {
9797
dictionary[key.stringValue] = intValue
98-
98+
9999
} else if let doubleValue = try? decode(Double.self, forKey: key) {
100100
dictionary[key.stringValue] = doubleValue
101-
101+
102102
} else if let stringValue = try? decode(String.self, forKey: key) {
103103
dictionary[key.stringValue] = stringValue
104-
105-
} else if let nestedDictionary = try? decode(Dictionary<String, Any>.self, forKey: key) {
104+
105+
} else if let nestedDictionary = try? decode([String: Any].self, forKey: key) {
106106
dictionary[key.stringValue] = nestedDictionary
107-
108-
} else if let nestedArray = try? decode(Array<Any>.self, forKey: key) {
107+
108+
} else if let nestedArray = try? decode([Any].self, forKey: key) {
109109
dictionary[key.stringValue] = nestedArray
110-
110+
111111
} else if try decodeNil(forKey: key) {
112112
dictionary[key.stringValue] = NSNull()
113113
} else {
114114
let context = DecodingError.Context(codingPath: [key], debugDescription: "Invalid Decoding Value")
115115
throw DecodingError.typeMismatch(type, context)
116116
}
117117
}
118-
118+
119119
return dictionary
120120
}
121121
}

Sources/CodablePlus/KeyedDecodingContainerProtocol+DefaultValues.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public extension KeyedDecodingContainerProtocol {
2020
///
2121
/// - parameter key: The key that the decoded value is associated with.
2222
/// - parameter defaultValue: Closure called to produce a value when needed.
23-
func decode<T>(_ key: Key, defaultValue: @autoclosure () -> T) -> T where T: Decodable {
23+
func decode<T: Decodable>(_ key: Key, defaultValue: @autoclosure () -> T) -> T {
2424
guard contains(key) else {
2525
return defaultValue()
2626
}
@@ -51,7 +51,7 @@ public extension KeyedDecodingContainerProtocol {
5151
///
5252
/// - parameter keys: the keys that the given value may be associate with.
5353
/// - parameter defaultValue: Closure called to produce a value when needed.
54-
func decode<T>(_ keys: [Key], defaultValue: @autoclosure () -> T) -> T where T: Decodable {
54+
func decode<T: Decodable>(_ keys: [Key], defaultValue: @autoclosure () -> T) -> T {
5555
guard !keys.isEmpty else {
5656
return defaultValue()
5757
}
@@ -62,11 +62,8 @@ public extension KeyedDecodingContainerProtocol {
6262
}
6363

6464
do {
65-
let value = try decode(T.self, forKey: key)
66-
return value
67-
} catch {
68-
69-
}
65+
return try decode(T.self, forKey: key)
66+
} catch {}
7067
}
7168

7269
return defaultValue()

Sources/CodablePlus/KeyedDecodingContainerProtocol+MultipleKeys.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public extension KeyedDecodingContainerProtocol {
1818
return true
1919
}
2020
}
21-
21+
2222
return false
2323
}
24-
24+
2525
/// Decodes a value of the given type for any of the given keys.
2626
///
2727
/// This method will attempt to decode data in the order the keys are given.
@@ -35,7 +35,7 @@ public extension KeyedDecodingContainerProtocol {
3535
/// one of the keys is not convertible to the requested type.
3636
/// - throws: `DecodingError.valueNotFound` if `self` has a null entry for all
3737
/// of the given keys.
38-
func decode<T>(_ type: T.Type, forKeys keys: [Key]) throws -> T where T: Decodable {
38+
func decode<T: Decodable>(_ type: T.Type, forKeys keys: [Key]) throws -> T {
3939
guard keys.count > 0 else {
4040
let context = DecodingError.Context(codingPath: [], debugDescription: "No Keys Specified")
4141
throw DecodingError.dataCorrupted(context)
@@ -70,7 +70,7 @@ public extension KeyedDecodingContainerProtocol {
7070
}
7171

7272
for key in keys {
73-
if let value = try self.decodeIfPresent(type, forKey: key) {
73+
if let value = try decodeIfPresent(type, forKey: key) {
7474
return value
7575
}
7676
}

0 commit comments

Comments
 (0)