0

我正在尝试使用 CFStringCompare 来比较字符串,但我不断得到一个Could not find an overload for == that accepts the supplied arguments.更具体地说,这段代码看起来像:

func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info: NSDictionary!)
{
let mediaType = info.objectForKey(UIImagePickerControllerMediaType) as String


if CFStringCompare(mediaType as NSString!,  kUTTypeMovie, compareOptions: 0) == CFComparisonResult.CompareEqualTo

{

   var moviePath : NSString = info.objectForKey(UIImagePickerControllerMediaURL).path

   if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath)
   {

      UISaveVideoAtPathToSavedPhotosAlbum(moviePath, nil, nil, nil)

   }

}
else ... 

我确定我只是搞砸了语法,但是我尝试将 mediaType 设为可选字符串并展开它:

let mediaType = info.objectForKey(UIImagePickerControllerMediaType) as String?

仍然could not find overload for ==

有任何想法吗?先感谢您!

4

1 回答 1

1

调用CFStringCompare() 方法不正确(注意:compareOptions是参数不是名称),试试这样:

   let compareResult = CFStringCompare(mediaType as NSString!, kUTTypeMovie, CFStringCompareFlags.CompareCaseInsensitive)

   if compareResult == CFComparisonResult.CompareEqualTo {

              println("Equal")

          }
    else {
              println("Not Equal")

         }

您可以根据需要提供不同的标志CFStringCompareFlags(0)

如果您不使用比较标志,可以通过以下方式轻松完成:

if mediaType == kUTTypeMovie {
//Equal
}
于 2014-06-30T11:48:16.733 回答