i’m getting this CI error:
error: 'init(unsafeUninitializedCapacity:initializingUTF8With:)'
is only available in macOS 11.0 or newer
try .init(unsafeUninitializedCapacity: 2 * MemoryLayout<Words>.size)
^
note: add 'if #available' version check
try .init(unsafeUninitializedCapacity: 2 * MemoryLayout<Words>.size)
^
note: add @available attribute to enclosing static method
func encodeBigEndian<Words>(_ words:Words, as _:String.Type = String.self,
^
note: add @available attribute to enclosing enum
enum Base16
^
error: fatalError
so i tried to fix it with
@available(macOS, introduced: 11.0)
@inlinable public static
func encodeBigEndian<Words>(_ words:Words, as _:String.Type = String.self,
by ascii:(UInt8) throws -> UInt8) rethrows -> String
{
}
@available(macOS, obsoleted: 11.0)
@inlinable public static
func encodeBigEndian<Words>(_ words:Words, as _:String.Type = String.self,
by ascii:(UInt8) throws -> UInt8) rethrows -> String
{
}
but that didn’t work:
Building for debugging...
error: invalid redeclaration of 'encodeBigEndian(_:as:by:)'
func encodeBigEndian<Words>(_ words:Words, as _:String.Type = String.self,
^
the only thing that worked was the (quite gnarly):
@inlinable public static
func encodeBigEndian<Words>(_ words:Words, as _:String.Type = String.self,
by ascii:(UInt8) throws -> UInt8) rethrows -> String
{
#if os(macOS)
if #available(macOS 11.0, *)
{
return .init(decoding: try Self.encodeBigEndian(words, as: [UInt8].self, by: ascii),
as: Unicode.UTF8.self)
}
else
{
return try .init(unsafeUninitializedCapacity: 2 * MemoryLayout<Words>.size)
{
var utf8:UnsafeMutableBufferPointer<UInt8> = $0
try Self.encodeBigEndian(words, utf8: &utf8, by: ascii)
return $0.count
}
}
#else
try .init(unsafeUninitializedCapacity: 2 * MemoryLayout<Words>.size)
{
var utf8:UnsafeMutableBufferPointer<UInt8> = $0
try Self.encodeBigEndian(words, utf8: &utf8, by: ascii)
return $0.count
}
#endif
}
is there a better way to deal with this?