【问题标题】:Cocoa/Finder: weird pathCocoa/Finder:奇怪的路径
【发布时间】:2011-06-03 16:42:04
【问题描述】:

我正在向查找器询问当前查找器窗口位置/路径/无论使用什么

NSString *path = [[finder insertionLocation] get];

导致这样的路径:

2011-06-03 18:38:55.132 CutIt[1980:903] <FinderFolder @0x1561d960: FinderFolder "eike" of FinderFolder "Users" of startupDisk of application "Finder" (185)>

有没有一种通用的方法可以将其转换为可用的路径,例如/users/eike,还是我必须自己修补一些东西?

【问题讨论】:

    标签: objective-c cocoa path finder scripting-bridge


    【解决方案1】:

    有点嵌套,但你可以随意分割:

    NSString *path = [[NSURL URLWithString:[[[finder insertionLocation] get] URL]] path];
    

    【讨论】:

    • 谢谢它的工作,虽然 xcode 警告我不兼容的指针
    【解决方案2】:

    如果有人感兴趣,这里有一种方法可以在没有投射警告的情况下获取路径:

    NSURL *insertLocation = [[[finder insertionLocation] get] URL];
    NSString *path = [[NSURL URLWithString:[NSString stringWithFormat:@"%@",insertLocation]] path];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-08
      • 2014-05-21
      • 2012-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多