The following code produces a warning in Swift6:
'init(cString:)' is deprecated: Use String(decoding: array, as: UTF8.self) instead, after truncating the null termination.
var size = 0
sysctlbyname("hw.model", nil, &size, nil, 0)
var modelIdentifier: [CChar] = Array(repeating: 0, count: size)
sysctlbyname("hw.model", &modelIdentifier, &size, nil, 0)
return String(cString: modelIdentifier)
Writing:
return String(decoding: modelIdentifier, as: UTF8.self)
produces an error:
Type of expression is ambiguous without a type annotation
How do I get rid of this ?