Objective c 将CFStringRef转换为NSString

Objective c 将CFStringRef转换为NSString,objective-c,macos,cocoa,Objective C,Macos,Cocoa,我正在尝试从主捆绑包中检索一些信息: - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { CFStringRef bundleVer = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey); NSString *appVersion = (__bridge NSStri

我正在尝试从主捆绑包中检索一些信息:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {    
    CFStringRef bundleVer = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey);
    NSString *appVersion = (__bridge NSString *)bundleVer;
}
我可以获得CFStringRef(在调试中,我可以看到与变量关联的正确值),但当我尝试将其转换为NSString时,我的appVersion变量的值为“null”(以前为nil)

我做错了什么

我用的是ARC

编辑:我的项目似乎有问题,即使是简单的静态赋值,也不能为每个NSString对象赋值,测试变量的值为(null)


它的工作区在我这边,它返回“2”

我将使用该代码而不是您当前的代码来获取相同的信息:




注意:我不确定您最终需要从bundle中获得哪些信息。

您的CFStringRef的值是否可能重复?我复制了你的代码,它完全可以在我的应用程序上运行。在我的应用程序中也可以正常运行。可能与拼写错误“bundle”有关。值为34,与我的bundle文件中的值相同。。。赋值后,appVersion从nil变为(null)
NSString *test = @"";
  CFStringRef boundleVer = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey);
  NSString *appVersion = (__bridge NSString *)(boundleVer);
NSString *_shortVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString *_version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];