title: Share attachment from Mail App with Share extension in iOS
body: <p>Now i'm working on the app that should implement share extension to share attachments from Mail App. It should support different file extensions (almost all types of documents). From Apple docs I understood that i have to use Predicate in my Info.plist, but in answers on SO i found that I have to use it in code. Now I'm stuck on that and can't proceed further. Here is the Predicate that I want to use from this <a href="https://stackoverflow.com/questions/26218627/ios-appextension-how-can-i-combine-nsextensionactivationrule-and-nspredicate">post</a>.</p>
  
  <pre><code>SUBQUERY (
              extensionItems,
              $extensionItem,
              SUBQUERY (
              $extensionItem.attachments,
              $attachment,
  
              (
                         ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.adobe.pdf"
                      || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
                      || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.png"
                      || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg"
                      || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg-2000"
                      || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.tiff"
                      || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.compuserve.gif"
                      || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.microsoft.bmp"
                      || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.microsoft.word.doc"
                      || ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "org.openxmlformats.wordprocessingml.document"
              )
  ).@count == $extensionItem.attachments.@count
  ).@count == 1
  </code></pre>
  
  <p>Can anyone advise how to use this predicate in my swift code:</p>
  
  <pre><code>    for attachment in content.attachments as! [NSItemProvider] {
          if attachment.hasItemConformingToTypeIdentifier(contentType) {
  
              attachment.loadItemForTypeIdentifier(contentType, options: nil) { data, error in
                  if error == nil {
                      let url = data as! NSURL
                      if let fileData = NSData(contentsOfURL: url) {
                          self.selectedFile = NSData(data: fileData)
                      }
                  } else {
  
                      let alert = UIAlertController(title: "Error", message: "Error loading file", preferredStyle: .Alert)
  
                      let action = UIAlertAction(title: "Error", style: .Cancel) { _ in
                          self.dismissViewControllerAnimated(true, completion: nil)
                      }
  
                      alert.addAction(action)
                      self.presentViewController(alert, animated: true, completion: nil)
                  }
              }
          }
      }
  </code></pre>
  
  <p>Here is my NSExtensionActivationRule:</p>
  
  <pre><code>        &lt;key&gt;NSExtensionActivationRule&lt;/key&gt;
          &lt;dict&gt;
              &lt;key&gt;NSExtensionActivationSupportsAttachmentsWithMaxCount&lt;/key&gt;
              &lt;integer&gt;1&lt;/integer&gt;
          &lt;/dict&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>