如何删除“NSBundle可能无法响应'-pathForResource:ofType'”警告

时间:2009-10-04 02:40:24

标签: c++ iphone objective-c objective-c++

我试图将objectiveForResource功能从objective-c暴露给C ++ 但是,我对objective-c很新,并且无法辨别如何在objective-c中使用c字符串作为参数。显然我在这里有错误的想法。 我如何让pathForResource使用c字符串作为参数?

这是我的功能:

    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;
}

1 个答案:

答案 0 :(得分:3)

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];