kholl kholl - 1 year ago 311
Swift Question

Path extension and MIME type of file in swift

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

Answer Source

Assuming you are receiving your data as NSData, follow this Post:

In Swift for example:

var c = [UInt32](count: 1, repeatedValue: 0)
(data as! NSData).getBytes(&c, length: 1)
switch (c[0]) {
case 0xFF, 0x89, 0x00:
case 0x47:
    println("unknown: \(c[0])")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download