stringswifttypesnsstringcfstring

Cannot invoke 'UTTypeEqual' with an argument list of type '(CFString!, CFString!)'


How do I get this to compile?

On the second line of this function:

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
    let mediaType = info[UIImagePickerControllerMediaType] as! CFString!
    if UTTypeEqual(mediaType, kUTTypeJPEG) {
        println("jpg")
    }
}

I get the compilation error:

Cannot invoke 'UTTypeEqual' with an argument list of type '(CFString!, CFString!)'

Solution

  • UITypeEqual returns Boolean, not Bool. The easiest way to deal with Boolean is to compare it to 0.

        if UTTypeEqual(mediaType, kUTTypeJPEG) != 0 {