【发布时间】:2012-05-23 07:46:12
【问题描述】:
我想知道什么相当于
+[NSString stringWithContentsOfURL:usedEncoding:error:] 在 CoreFoundation 中?
我知道这次我可以使用 (__bridge NSString *) 的东西,我宁愿让我的生活复杂一点,并了解一下在 Cocoa 出现之前这是如何完成的...... :)
按照我的口味,在objective-c中有几行来做一个东西是很丑的
...
CFErrorRef error = NULL;
CFURLRef fileURL = CFBundleCopyResourceURL(bundle,
CFSTR("file"),
CFSTR("txt"),
NULL);
// Ugly piece of objc code in my whole C source file :(
NSError *nsError = (__bridge NSError *)(error);
NSString *nsString = [NSString stringWithContentsOfURL:(__bridge NSURL *)fileURL
usedEncoding:NULL
error:&nsError];
CFStringRef fileContents = (__brigde CFStringRef)nsString;
...
【问题讨论】:
标签: objective-c c core-foundation