0
let cStringRef : CFStringRef = CFStringCreateWithCString(nil, NSBundle.mainBundle().pathForResource("Luffy", ofType: "mp3")! , kCFStringEncodingMacRoman)

this encoding isn't working, though it is present in the Documentation.

to get MacRoman, I used CFStringGetSystemEncoding()

My question is how to retrieve a CFStringEncoding other than this.

Krishna
  • 673
  • 3
  • 6
  • 21

2 Answers2

0

If you just want to convert the path of Luffy.mp3 to CFString, use this:

let cStringRef = NSBundle.mainBundle().pathForResource("Luffy", ofType: "mp3")! as CFString

Edit: if you want to go the long way:

let path = NSBundle.mainBundle().pathForResource("Luffy", ofType: "mp3")!
let cString = path.cStringUsingEncoding(NSMacOSRomanStringEncoding)!

let cfString = CFStringCreateWithCString(nil, cString, CFStringBuiltInEncodings.MacRoman.rawValue)
Code Different
  • 90,614
  • 16
  • 144
  • 163
  • yes, but the question is, any other method to get a specific encoding? because kCFStringEncodingMacRoman doesn't work. – Krishna Jun 25 '16 at 04:32
0

That code doesn't make any sense whatsoever.

The path is an NSString, directly compatible with String and with CFStringRef. There is no C string in sight anywhere.

I really recommend that you figure out why on earth you want to use a CFString (which is more than unusual) and remove that usage. Or if you have been copying some code from the internet go and find some newer code to copy. If your Swift code uses a CFStringRef, you are doing something WRONG.

gnasher729
  • 51,477
  • 5
  • 75
  • 98