Skip to content

Commit 8b54330

Browse files
alexey1312claude
andcommitted
fix(linux): use #if os(macOS) instead of canImport for YYJSON
canImport(YYJSON) returns true on Linux because SwiftPM resolves the module in the dependency graph, but Cyyjson C library isn't linkable. Using os(macOS) provides deterministic compile-time check. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b5fb0f7 commit 8b54330

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

Sources/ExFigCore/JSON/JSONCodec.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
#if canImport(YYJSON)
3+
#if os(macOS)
44
import YYJSON
55
#endif
66

@@ -14,7 +14,7 @@ public enum JSONCodec {
1414

1515
/// Encode value to JSON data.
1616
public static func encode(_ value: some Encodable) throws -> Data {
17-
#if canImport(YYJSON)
17+
#if os(macOS)
1818
try YYJSONEncoder().encode(value)
1919
#else
2020
try JSONEncoder().encode(value)
@@ -23,7 +23,7 @@ public enum JSONCodec {
2323

2424
/// Encode value to pretty-printed JSON.
2525
public static func encodePretty(_ value: some Encodable) throws -> Data {
26-
#if canImport(YYJSON)
26+
#if os(macOS)
2727
var encoder = YYJSONEncoder()
2828
encoder.writeOptions = [.prettyPrinted]
2929
return try encoder.encode(value)
@@ -38,7 +38,7 @@ public enum JSONCodec {
3838
///
3939
/// Use for hashing where key order matters.
4040
public static func encodeSorted(_ value: some Encodable) throws -> Data {
41-
#if canImport(YYJSON)
41+
#if os(macOS)
4242
var encoder = YYJSONEncoder()
4343
encoder.writeOptions = [.sortedKeys]
4444
return try encoder.encode(value)
@@ -54,7 +54,7 @@ public enum JSONCodec {
5454
/// Use for Contents.json in xcassets where human-readable output
5555
/// with deterministic key order is needed.
5656
public static func encodePrettySorted(_ value: some Encodable) throws -> Data {
57-
#if canImport(YYJSON)
57+
#if os(macOS)
5858
var encoder = YYJSONEncoder()
5959
encoder.writeOptions = [.prettyPrintedTwoSpaces, .sortedKeys]
6060
return try encoder.encode(value)
@@ -67,7 +67,7 @@ public enum JSONCodec {
6767

6868
/// Decode JSON data to type.
6969
public static func decode<T: Decodable>(_ type: T.Type, from data: Data) throws -> T {
70-
#if canImport(YYJSON)
70+
#if os(macOS)
7171
try YYJSONDecoder().decode(type, from: data)
7272
#else
7373
try JSONDecoder().decode(type, from: data)
@@ -76,7 +76,7 @@ public enum JSONCodec {
7676

7777
/// Decode JSON data with ISO8601 date decoding strategy.
7878
public static func decodeWithISO8601Date<T: Decodable>(_ type: T.Type, from data: Data) throws -> T {
79-
#if canImport(YYJSON)
79+
#if os(macOS)
8080
var decoder = YYJSONDecoder()
8181
decoder.dateDecodingStrategy = .iso8601
8282
return try decoder.decode(type, from: data)
@@ -91,7 +91,7 @@ public enum JSONCodec {
9191
///
9292
/// Use for checkpoint files where dates and human-readability matter.
9393
public static func encodeWithISO8601DatePretty(_ value: some Encodable) throws -> Data {
94-
#if canImport(YYJSON)
94+
#if os(macOS)
9595
var encoder = YYJSONEncoder()
9696
encoder.dateEncodingStrategy = .iso8601
9797
encoder.writeOptions = [.prettyPrinted]

0 commit comments

Comments
 (0)