title: Swift Present Popover View from a UIButton
body: <p><strong>Question</strong></p>
  <p>Hello. How, in Swift, do I present a popover from a  Storyboard-created UIButton, in order to get photos from the photo library? I have figured out the photos library stuff, just not the presenting of the view controller.</p>
  <p><strong>Research</strong></p>
  <p>I found instructions on how to do a similar thing from a BarButtonItem about half way down <a href="http://makeapppie.com/2014/12/04/swift-swift-using-the-uiimagepickercontroller-for-a-camera-and-photo-library/" rel="nofollow noreferrer">here</a>.</p>
  <p><strong>Current Attempts</strong></p>
  <p>I am trying the following code.</p>
  <pre><code>self.imagePicker.delegate = self
  self.imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum;
  self.imagePicker.allowsEditing = false
              
  self.imagePicker.modalPresentationStyle = .Popover
  presentViewController(self.imagePicker, animated: true, completion: nil)//4
  self.imagePicker.popoverPresentationController?.photo = sender
  </code></pre>
  <p>with <code>photo</code> being the UIButton that I want to present this modal view from. For simplicity's sake, only the parts of the code related to presenting the view are given.</p>
  <p>I have also tried</p>
  <pre><code>self.imagePicker.delegate = self
              self.imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum;
              self.imagePicker.allowsEditing = false
              
              self.imagePicker.modalPresentationStyle = .Popover
              self.imagePicker.popoverPresentationController!.sourceRect = self.photo.bounds
              self.presentViewController(self.imagePicker, animated: true, completion: nil)
  </code></pre>
  <p>which gives a sigabrt,</p>
  <p><strong>Action</strong></p>
  <p>When the above code is typed, Xcode gives the error</p>
  <blockquote>
  <p>&quot;use of unresolved identifier 'sender'&quot;</p>
  </blockquote>
  <p><strong>Expected Action</strong></p>
  <p>I want a popover containing the photo library to be presented, as shown in this image:</p>
  <p><a href="https://i.stack.imgur.com/nGz0x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nGz0x.png" alt="Expected Behavior" /></a></p>
  <p>What am I doing wrong? Thanks!</p>