0

I wrote some code in a command-line-tool application, and it run correctly. But when I brought it to my iOS application, it went wrong.

The essentil code is:

let foo = CFStringConvertEncodingToNSStringEncoding(CFStringEncoding(CFStringEncodings.GBK_95.rawValue))
let bar = String.Encoding(rawValue: foo)
print("foo=\(foo)")
print("bar=\(bar)")

When I run these code in a command-line-tool application, I got:

foo=2147485233
bar=Chinese (GBK)

When I run these code in a iOS application, I got:

foo=2147485233
bar=

It seems amazing that the code got different result in two environment. Does bar get an empty Enumeration value?How can I resolve it?

enter image description here

enter image description here

Harshal Valanda
  • 5,331
  • 26
  • 63

1 Answers1

0

Well...I got help from this

Use GB_18030_2000 instead.

let encoding = String.Encoding(rawValue: CFStringConvertEncodingToNSStringEncoding(CFStringEncoding(CFStringEncodings.GB_18030_2000.rawValue)))