title: How to sent image using XMPPStream XMPP Framework in Swift Language?
body: <p>I used   </p>
  
  <blockquote>
    <p>pod 'XMPPFramework'</p>
  </blockquote>
  
  <p>in my Demo Project. I made connections, and put delegate methods appropriately. </p>
  
  <p>I made simple chat, where I am sending message using </p>
  
  <pre><code> let msg = XMPPMessage(type: "chat", to: senderJID)
   msg.addBody(message)
   self.appDelegate.xmppStream.sendElement(msg)
  </code></pre>
  
  <p>On receiving end, I am doing </p>
  
  <pre><code>func xmppStream(sender: XMPPStream!, didReceiveMessage message: XMPPMessage!) {
  
  messageStr = messageStr + message.body()
  print("Did receive message \(messageStr)")
  
  }
  </code></pre>
  
  <p>Now I want to sent Image. I browsed and found some code, using attachment, like below, in objective-c.</p>
  
  <pre><code>NSData *dataF = UIImagePNGRepresentation(SendImage);
           NSString *imgStr=[dataF base64Encoding];
  
           NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
           [body setStringValue:messageStr];
  
           NSXMLElement *imgAttachement = [NSXMLElement elementWithName:@"attachment"];
           [imgAttachement setStringValue:imgStr];
  
           NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
           [message addAttributeWithName:@"type" stringValue:@"chat"];
           [message addAttributeWithName:@"to" stringValue:chatWithUser];
           [message addChild:body];
           [message addChild:imgAttachement];      
  
           [self.xmppStream sendElement:message]; 
  </code></pre>
  
  <p>My Swift code , which I converted from above Objective-C Code.</p>
  
  <pre><code>var dataF = UIImagePNGRepresentation(image)
          var imgStr = dataF.base64Encoding()
  
          let root = NSXMLElement(name: "find_sites")
  
          var body = NSXMLElement.elementWithName("body")
          body.stringValue = messageStr
          var imgAttachement = NSXMLElement.elementWithName("attachment")
          imgAttachement.stringValue = imgStr
          var message = NSXMLElement.elementWithName("message")
          message.addAttributeWithName("type", stringValue: "chat")
          message.addAttributeWithName("to", stringValue: senderJID)
          message.addChild(body)
          message.addChild(imgAttachement)
          self.xmppStream.sendElement(message)
  </code></pre>
  
  <p>If I convert this code into Swift, I am getting error on NSXMLElement, what should I do, how can I achieve it. </p>
  
  <p>I also read <code>XMPPStream class</code>, I didn't find anything productive. </p>
  
  <p>Thanks.</p>