swift中的路径扩展和MIME类型的文件 [英] Path extension and MIME type of file in swift

查看:213
本文介绍了swift中的路径扩展和MIME类型的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在快速学习,我创建了一个包含显示图像的单元格的表,以及按MIME TYPE(使用路径扩展名)分组的类。
我有关于扩展的问题。
如果图像(例如,它可能是视频或pdf)是从互联网上拍摄的,我不确定他们是否有扩展名或者不是
我如何获得MIMEtype我的文件系统中没有使用路径扩展名的文件?
PS:抱歉我的英文不好,这不是我的母语

I'm learning swift , and I made a table with cells that show an image ,and classes in groups by MIME TYPE (using path extension). I had a question about extensions. If the images (for example, it could be a video or a pdf) are taken from internet , i'm not sure if they have the extension or not how can I get the MIMEtype of a file inside my file System without using path extension ? PS :Sorry for my bad english it's not my native language

推荐答案

假设您收到的数据为NSData,请按照以下文章发布: https://stackoverflow.com/a/ 5042365/2798777

Assuming you are receiving your data as NSData, follow this Post: https://stackoverflow.com/a/5042365/2798777

以Swift为例:

var c = [UInt32](count: 1, repeatedValue: 0)
(data as! NSData).getBytes(&c, length: 1)
switch (c[0]) {
case 0xFF, 0x89, 0x00:
    println("image")
case 0x47:
    println("gif")
default: 
    println("unknown: \(c[0])")
}

这篇关于swift中的路径扩展和MIME类型的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆