相关疑难解决方法(0)

如何在Swift中的路径中找到文件UTI for file,withouth pathExtension

我一直试图转换这个代码,我从这个例子(在Objective-c中)没有运气.

    String *path; // contains the file path

    // Get the UTI from the file's extension:

    CFStringRef pathExtension = (__bridge_retained CFStringRef)[path pathExtension];
    CFStringRef type = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension, NULL);
    CFRelease(pathExtension);

    // The UTI can be converted to a mime type:

    NSString *mimeType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass(type, kUTTagClassMIMEType);
    if (type != NULL)
        CFRelease(type);
Run Code Online (Sandbox Code Playgroud)

我的代码是这样的

    import MobileCoreServices
    let path: String?
    let pathExt = path.pathExtension as CFStringRef
    let type = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension, NULL);
    let mimeType = UTTypeCopyPreferredTagWithClass(type, kUTTagClassMIMEType)
    if type != Null …
Run Code Online (Sandbox Code Playgroud)

uti ios swift swift2

8
推荐指数
1
解决办法
4105
查看次数

标签 统计

ios ×1

swift ×1

swift2 ×1

uti ×1