Question

I am trying to expose the pathForResource functionality to C++ from objective-c.
However, I am very new to objective-c and have not been able to discern how to use a c string as an argument in objective-c. clearly I have the wrong idea here. how do i get pathForResource to use c strings as an argument?

here is my function:

    static std::string getAssetPath(std::string name, std::string ending)
{

 const char * nameChar = name.c_str();
 const char * endingChar = ending.c_str();
 NSString* assetPath = [NSBundle pathForResource:&nameChar
            ofType:&endingChar];
 std::string str;
 str = std::string([assetPath cStringUsingEncoding: NSASCIIStringEncoding]);
 return str;
}
Was it helpful?

Solution

NSString* nameChar = [NSString stringWithCString:name.c_str() encoding:NSUTF8StringEncoding];    
NSString* endingChar = [NSString stringWithCString:ending.c_str() encoding:NSUTF8StringEncoding];

NSString* assetPath = [[NSBundle mainBundle] pathForResource:nameChar ofType:endingChar];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top