Ben Zotto
Ben Zotto

Reputation: 71008

What is the correct encoding for filesystem path strings?

When I take a path in an NSString and turn around and use it in a C API, for example:

CGDataProviderRef CGDataProviderCreateWithFilename(const char *filename );

What is the correct encoding for the path when flattening to a char*? UTF8? (ASCII??)

I feel like this should be either obvious, or obviously documented, but I'm having trouble thinking and/or finding the answer.

Upvotes: 3

Views: 1301

Answers (2)

jiminybob99
jiminybob99

Reputation: 873

an example that worked for me using the above answer

NSString *path =@"/Users/ethansanford/Desktop/mutable string logic/mutable string logic/long-arrow-right.png" ;
CGDataProviderRef provider = CGDataProviderCreateWithFilename(path.fileSystemRepresentation);
imageRef2 =CGImageCreateWithPNGDataProvider(provider, NULL, false, kCGRenderingIntentDefault);

Upvotes: 0

Kurt Revis
Kurt Revis

Reputation: 27984

Use -[NSString fileSystemRepresentation].

Upvotes: 4

Related Questions