swiftcfstring

CFStringCompare Overload


I am attempting to use CFStringCompare to compare strings, but I keep getting a Could not find an overload for == that accepts the supplied arguments. More specifically, the bit of code looks like:

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 ... 

I'm sure I'm just screwing up the syntax, however I've tried making mediaType an Optional String and unwrapping it:

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

and still could not find overload for ==.

Any ideas? Thank you in advance!


Solution

  • Calling CFStringCompare() method not correct (note: compareOptions is a parameter not a name) , Try like this :

       let compareResult = CFStringCompare(mediaType as NSString!, kUTTypeMovie, CFStringCompareFlags.CompareCaseInsensitive)
    
       if compareResult == CFComparisonResult.CompareEqualTo {
    
                  println("Equal")
    
              }
        else {
                  println("Not Equal")
    
             }
    

    You can provide different flags as u need CFStringCompareFlags(0) in your case.

    If you are not using compare flags it can be easily done with :

    if mediaType == kUTTypeMovie {
    //Equal
    }