Skip to content

Commit f58773e

Browse files
committed
Remove UserDefaults when building for web assembly
1 parent bc258e5 commit f58773e

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

Sources/UserDefaults+Codable.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import Foundation
3333

34+
#if !os(WASI)
3435
public extension UserDefaults {
3536

3637
func encode<T: Encodable>(_ value: T, forKey key: String) throws {
@@ -56,3 +57,4 @@ public extension UserDefaults {
5657
}
5758
}
5859
}
60+
#endif

Tests/KeyValueDecoderTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ final class KeyValueDecoderTests: XCTestCase {
732732
}
733733
}
734734

735+
#if !os(WASI)
735736
func testPlistCompatibleDecoder() throws {
736737
let plistAny = try PropertyListEncoder.encodeAny([1, 2, Int?.none, 4])
737738
XCTAssertEqual(
@@ -752,6 +753,7 @@ final class KeyValueDecoderTests: XCTestCase {
752753
[1, 2, Int?.none, 4]
753754
)
754755
}
756+
#endif
755757
}
756758

757759
func AssertThrowsDecodingError<T>(_ expression: @autoclosure () throws -> T,
@@ -890,6 +892,7 @@ struct SomeTypes: Codable, Equatable {
890892
var tString: String?
891893
}
892894

895+
#if !os(WASI)
893896
private extension PropertyListEncoder {
894897
static func encodeAny<T: Encodable>(_ value: T) throws -> Any {
895898
let data = try PropertyListEncoder().encode(value)
@@ -903,3 +906,4 @@ private extension JSONEncoder {
903906
return try JSONSerialization.jsonObject(with: data, options: [])
904907
}
905908
}
909+
#endif

Tests/KeyValueEncoderTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,15 @@ final class KeyValueEncodedTests: XCTestCase {
638638
)
639639
}
640640

641+
#if !os(WASI)
641642
func testPlistCompatibleEncoder() throws {
642643
let keyValueAny = try KeyValueEncoder.makePlistCompatible().encode([1, 2, Int?.none, 4])
643644
XCTAssertEqual(
644645
try PropertyListDecoder.decodeAny([Int?].self, from: keyValueAny),
645646
[1, 2, Int?.none, 4]
646647
)
647648
}
649+
#endif
648650

649651
func testEncoder_Encodes_Dates() {
650652
let date = Date()
@@ -764,12 +766,14 @@ extension KeyValueEncoder.EncodedValue {
764766
}
765767
}
766768

769+
#if !os(WASI)
767770
private extension PropertyListDecoder {
768771
static func decodeAny<T: Decodable>(_ type: T.Type, from value: Any?) throws -> T {
769772
let data = try PropertyListSerialization.data(fromPropertyList: value as Any, format: .xml, options: 0)
770773
return try PropertyListDecoder().decode(type, from: data)
771774
}
772775
}
776+
#endif
773777

774778
private extension JSONDecoder {
775779
static func decodeAny<T: Decodable>(_ type: T.Type, from value: Any?) throws -> T {

Tests/UserDefaults+CodableTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import Foundation
3535
import XCTest
3636

37+
#if !os(WASI)
3738
final class UserDefaultsCodableTests: XCTestCase {
3839

3940
func testEncodes_Single() {
@@ -331,3 +332,4 @@ private extension UserDefaults {
331332
return UserDefaults(suiteName: "mock")!
332333
}
333334
}
335+
#endif

0 commit comments

Comments
 (0)