i trying replicate objective c cocoa in swift. until come across following:
// set new type , creator: unsigned long type = 'text'; unsigned long creator = 'pdos'; how can create int64s (or correct swift equivalent) single quote character literals this?
i'm using in cocoa scripting apps, considers characters > 0x80 correctly
func ostypefrom(string : string) -> uint { var result : uint = 0 if let data = string.datausingencoding(nsmacosromanstringencoding) { let bytes = unsafepointer<uint8>(data.bytes) in 0..<data.length { result = result << 8 + uint(bytes[i]) } } return result } edit:
alternatively
func fourcharcodefrom(string : string) -> fourcharcode { assert(string.characters.count == 4, "string length must 4") var result : fourcharcode = 0 char in string.utf16 { result = (result << 8) + fourcharcode(char) } return result }
Comments
Post a Comment