无法使用类型为'(CFString!,CFString!)'的参数列表调用'UTTypeEqual'

时间:2015-05-07 00:21:22

标签: string swift types nsstring cfstring

如何编译?

在此功能的第二行:

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

我收到编译错误:

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

1 个答案:

答案 0 :(得分:1)

UITypeEqual返回Boolean,而不是Bool。处理Boolean的最简单方法是将其与0进行比较。

    if UTTypeEqual(mediaType, kUTTypeJPEG) != 0 {