0

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!

nhgrif
  • 61,578
  • 25
  • 134
  • 173
Kengineer
  • 3
  • 4

1 Answers1

1

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
}
Yatheesha
  • 10,412
  • 5
  • 42
  • 45
  • That seemed to do the trick! I'm translating from Objective-C to Swift, so I never would have caught that without your keen eye. Thanks! – Kengineer Jun 30 '14 at 14:05