iOS5使用ARC:int到NSDictionary的隐式转换
我正在使用 ARC 来更新我的旧项目。 我有一个“Filehelper”类,在其中我使用 c 函数,例如几乎每个项目中我需要的方法。 (例如加载plist等..)
ViewController
NSDictionary* dictionary = getDictionaryFromPlistWithName(@"TestFile", @"plist");
Filehelper.m
#pragma Returns content of plist as NSDictionary
NSDictionary* getDictionaryFromPlistWithName(NSString* fileName, NSString* pathExtension) {
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:pathExtension];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path];
if(fileExists){
NSDictionary* dictionary = [NSDictionary dictionaryWithContentsOfFile:path];
return dictionary;
}
else{
[NSException raise:@"File not found" format:@"path %@", path];
return nil;
}
}
我收到此错误:
*错误:自动引用计数问题:ARC 不允许将“int”隐式转换为“NSDictionary ”
有什么想法可以修复它以在 iOS 5 中使用它吗? 我读过一些我需要使用的东西(__bridge NSDictionary*),但这没有帮助。
附言。 对于您已经需要的课程,您的工作流程是什么?也使用 C 函数吗?= 最好的方法是什么?
i´m using ARC to update my old project.
I have a "Filehelper" class in which i use c-functions e.g. for methods i need in almost every projects. (eg.load plist, etc..)
ViewController
NSDictionary* dictionary = getDictionaryFromPlistWithName(@"TestFile", @"plist");
Filehelper.m
#pragma Returns content of plist as NSDictionary
NSDictionary* getDictionaryFromPlistWithName(NSString* fileName, NSString* pathExtension) {
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:pathExtension];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path];
if(fileExists){
NSDictionary* dictionary = [NSDictionary dictionaryWithContentsOfFile:path];
return dictionary;
}
else{
[NSException raise:@"File not found" format:@"path %@", path];
return nil;
}
}
I get this error:
*error: Automatic Reference Counting Issue: Implicit conversion of 'int' to 'NSDictionary ' is disallowed with ARC
Any ideas how to fix it to use it with iOS 5?
I´ve read something that i need to use (__bridge NSDictionary*), but that didn´t help.
PS.
What´s your workflow for classes which you already need? Use C-functions, too?=
What´s the best way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里最可能的问题是您忘记
#include
您的头文件。我敢打赌,还有更多警告您会忽略,特别是一条警告,其中写着“getDictionaryFromPlistWithName 的未知签名,假设它返回 int”之类的内容。仔细阅读您的警告,切勿忽略它们(我强烈建议所有 ObjC 项目使用 -Werror)。The most likely problem here is that you forgot to
#include
your header file. I bet there are further warnings that you're ignoring, particularly one that says something like "unknown signature for getDictionaryFromPlistWithName, assuming it returns int". Read through your warnings and never ignore them (I strongly recommend -Werror for all ObjC projects).