Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSPNGFileType - not found in Swift?

Today, I found something strange :

I wanted to write this code in swift :

    NSData *data = [myImage representationUsingType: NSPNGFileType properties: nil];

In swift it's look like this:

var data: NSData = imageToSave?.representationUsingType( NSPNGFileType ,
            properties: nil)

The problem is that the compiler say : " Use of unresolved identifier 'NSPNGFileType'". Does anyone have any idea why ?

Thanks, and sorry for my english !

like image 360
C-Viorel Avatar asked Feb 12 '23 15:02

C-Viorel


2 Answers

You probably have to use .NSPNGFileType, or more explicitly NSBitmapImageFileType.NSPNGFileType

like image 174
Antonio Avatar answered Feb 16 '23 03:02

Antonio


In Swift 3 this has changed to simply .PNG or as the full version NSBitmapImageFileType.PNG (docs).

like image 37
Maccesch Avatar answered Feb 16 '23 02:02

Maccesch