c++ - 如何删除 "NSBundle may not respond to ' -pathForResource :ofType' "warning

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

我正在尝试从 objective-c 向 C++ 公开 pathForResource 功能。
但是,我对 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;
}

最佳答案

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

关于c++ - 如何删除 "NSBundle may not respond to ' -pathForResource :ofType' "warning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1515460/

相关文章:

ios - 不同iOS版本之间的应用程序迁移

c++ - DFS 和替换为 for_each

c++ - 将函数传递给函数并使用头文件时出错

iPhone - 如何使用 facebook iOS sdk 发送应用请求

iphone - NSFetchRequest/谓词问题

iphone - 有没有办法获取应用程序图标角标(Badge)编号?

objective-c - 核心数据方法的类扩展

c++ - 为什么我得到的 C 程序值是垃圾值?

c++ - 在 clang 3.3/3.4 与 gcc 4.8 下调试时不显示符号

ios - 如何在 iOS 的边框内获取带有标题的 View 的边框?