From 6ef2b9e8224bab2cde3a18487e15fd17d2fc324f Mon Sep 17 00:00:00 2001 From: Tejas Sharma Date: Mon, 1 Apr 2024 09:34:54 -0700 Subject: [PATCH] just use String instead of StringProtocol for pre-5.6 --- Sources/Yams/Encoder.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sources/Yams/Encoder.swift b/Sources/Yams/Encoder.swift index fd17bac3..d0c23b94 100644 --- a/Sources/Yams/Encoder.swift +++ b/Sources/Yams/Encoder.swift @@ -226,18 +226,30 @@ extension _Encoder: SingleValueEncodingContainer { func encode(_ value: T) throws where T: YAMLEncodable { assertCanEncodeNewValue() node = value.box() +#if swift(>=5.6) if let stringValue = value as? (any StringProtocol), stringValue.contains("\n") { node.scalar?.style = newlineScalarStyle } +#else + if let stringValue = value as? String, stringValue.contains("\n") { + node.scalar?.style = newlineScalarStyle + } +#endif } func encode(_ value: T) throws where T: Encodable { assertCanEncodeNewValue() if let encodable = value as? YAMLEncodable { node = encodable.box() +#if swift(>=5.6) if let stringValue = value as? (any StringProtocol), stringValue.contains("\n") { node.scalar?.style = newlineScalarStyle } +#else + if let stringValue = value as? String, stringValue.contains("\n") { + node.scalar?.style = newlineScalarStyle + } +#endif } else { try value.encode(to: self) }