title: Save image in Realm
body: <p>I'm trying to pick image from device's Photo Library in method:</p>
  
  <pre><code>func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
  {
  
      userPhoto.image = info[UIImagePickerControllerOriginalImage] as! UIImage?
      userPhoto.contentMode = .scaleAspectFill
      userPhoto.clipsToBounds = true
  
      dismiss(animated: true, completion: nil)
  }
  </code></pre>
  
  <p>and save this picture in Realm (as NSData):</p>
  
  <pre><code>asset.assetImage = UIImagePNGRepresentation(userPhoto.image!)! as NSData?
  </code></pre>
  
  <p>...</p>
  
  <pre><code>   try! myRealm.write
          {
              user.assetsList.append(asset)
              myRealm.add(user)
          }
  </code></pre>
  
  <p>After build succeeded and trying to pick and save image (in the app) i have app error:
  'Binary too big'</p>
  
  <p>What i'm doing wrong?</p>
  
  <p>P.S. Sorry for my English :)</p>
  
  <hr>
  
  <p>After some actions i have this code. But it's overwrite my image.</p>
  
  <pre><code>func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
  {
      let imageUrl = info[UIImagePickerControllerReferenceURL] as! NSURL
      let imageName = imageUrl.lastPathComponent
      let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
      let photoURL = NSURL(fileURLWithPath: documentDirectory)
      let localPath = photoURL.appendingPathComponent(imageName!)
      let image = info[UIImagePickerControllerOriginalImage]as! UIImage
      let data = UIImagePNGRepresentation(image)
  
      do
      {
          try data?.write(to: localPath!, options: Data.WritingOptions.atomic)
      }
      catch
      {
          // Catch exception here and act accordingly
      }
  
      userPhoto.image = image
      userPhoto.contentMode = .scaleAspectFill
      userPhoto.clipsToBounds = true
  
      urlCatch = (localPath?.path)!
      self.dismiss(animated: true, completion: nil);
  }
  </code></pre>