【发布时间】:2012-02-06 14:05:58
【问题描述】:
我正在使用 ARC 来更新我的旧项目。 我有一个“Filehelper”类,我在其中使用 c 函数,例如对于我在几乎每个项目中都需要的方法。 (eg.load plist, etc..)
视图控制器
NSDictionary* dictionary = getDictionaryFromPlistWithName(@"TestFile", @"plist");
文件助手.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 函数?= 最好的方法是什么?
【问题讨论】:
-
哪一行产生错误?
-
为什么你使用 C 风格的函数
NSDictionary* getDictionaryFromPlistWithName(NSString* fileName, NSString* pathExtension)声明而不是像- (NSDictionary *) dictionaryFromPlistWithName:(NSString *) fileName extension:(NSString *) pathExtension这样声明 Objective-C 方法? -
@AndreyZ。因为也许他希望这是一个 C 函数,而不一定要附加到特定的类?
-
是否还有其他警告,例如关于找不到函数定义?
标签: ios automatic-ref-counting