NSData encoding

梦想与她 提交于 2019-12-12 06:10:02

问题


Currently, I'm trying to parse an NSData in my iOS app. Problem is, I can't seem to find a proper hebrew encoding for parsing. I must decode the data using the Windows-1255 encoding (hebrew encoding type for windows) or ISO 8859-8 encoding, or I'll get plain gibberish. The closest I've got to solving the issue was using

CFStringConvertEncodingToNSStringEncoding(CFStringEncodings.ISOLatinHebrew)

yet it throws 'CFStringEncodings' is not convertible to 'CFStringEncoding' (notice Encodings vs Encoding).

What can I do in order to encode the data correctly?

Thanks!


回答1:


The problem is that CFStringEncodings is an enumeration based on CFIndex (which in turn is a type alias for Int), whereas CFStringEncoding is a type alias for UInt32. Therefore you have to convert the .ISOLatinHebrew value explicitly to a CFStringEncoding:

let cfEnc = CFStringEncodings.ISOLatinHebrew
let enc = CFStringConvertEncodingToNSStringEncoding(CFStringEncoding(cfEnc.rawValue))



回答2:


Turns out I needed to get my hands a bit dirty. I saw that CFStringEncodings has a relation to the file CFStringEncodingsExt.h, so I searched the file for some help. Suddenly I came across a huge CF_ENUM that included exactly what I needed- all of the CFStringEncodings by their UInt32 value!

So it has turned out that kCFStringEncodingISOLatinHebrew = 0x0208, /* ISO 8859-8 */

I encourage everyone who is facing this encoding issue to go to that file and search for his needed encoding.



来源:https://stackoverflow.com/questions/27861724/nsdata-encoding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!