In the code below I'm trying to compare the first six bytes of some Data with a utf8 string literal which (in C) I could represent as "\0x93NUMPY"
. But that's not a valid way of representing a string literal in Swift. So I've used the unicode character u\0093
, which is two bytes long in utf8, and indexed the string data from 1..7, which works, but ...Yuk.
let magic = "\u{0093}NUMPY".data(using: .utf8)![1..<7]
guard Data![0..<6] == magic else {
return
}
How should I rewrite this code to avoid the confusing indexing issues, while still using a string literal?