title: Alamofire NSURLRequest Ambiguous use of URLString
body: <p>So I'm relatively new to swift and recently I started a new project that required several network request to a JSON api on a remote server, so i decided to use Alamofire library (version 1.1 included via cocoapods) following these tutorials:</p>
  
  <p><a href="http://www.raywenderlich.com/85080/beginning-alamofire-tutorial" rel="nofollow">http://www.raywenderlich.com/85080/beginning-alamofire-tutorial</a>
  <a href="http://www.raywenderlich.com/87595/intermediate-alamofire-tutorial" rel="nofollow">http://www.raywenderlich.com/87595/intermediate-alamofire-tutorial</a></p>
  
  <p>Just in case it's relevant, here is the code i used in the podfile to include the Alamofire library:</p>
  
  <pre><code>source 'https://github.com/CocoaPods/Specs.git'
  platform :ios, '8.0'
  use_frameworks!
  
  pod 'Alamofire', '~&gt; 1.1'
  </code></pre>
  
  <p>One requirement was that images needed to be downloaded and cached for an specific tableview. Following the tutorials, i built an extension of the Alamofire.Request class the framework provides:</p>
  
  <pre><code>extension Alamofire.Request {
  
      class func imageResponseSerializer() -&gt; Serializer {
          return { request, response, data in
              if data == nil {
                  return (nil, nil)
              }
  
              let image = UIImage(data: data!, scale: UIScreen.mainScreen().scale)
  
              return (image, nil)
          }
      }
  
      func responseImage(completionHandler: (NSURLRequest, NSHTTPURLResponse?, UIImage?, NSError?) -&gt; Void) -&gt; Self {
          return response(serializer: Request.imageResponseSerializer(), completionHandler: { (request, response, image, error) in
              completionHandler(request, response, image as? UIImage, error)
          })
      }
  
  }
  </code></pre>
  
  <p>With this i requested images with</p>
  
  <pre><code>Alamofire.Request(.GET, "IMAGE URL").responseImage(){
       (request, _, image, error) in
  
       // Logic used to display image and save it to the cache
  
  }
  </code></pre>
  
  <p>Testing the download without the cache shows that it works and i can display them, but the problem arises when i need the original URL as the key to my NSCache, but every time i try to access the property (request.URLString), xcode always throws a lot of errors.</p>
  
  <p>Trying to access the property like this:</p>
  
  <pre><code>self.imageCache.setObject(image!, forKey: request.URLString)
  </code></pre>
  
  <p>throws "Ambiguous use of URLString" in the editor, and trying to compare it with other string values always throws an error saying "Cannot invoke 'operand' with an argument list of type '($T6??, String)'"</p>
  
  <p>** Note that the number in $T6?? varies depending on where i'm using it</p>
  
  <p>I tried searching for references to this kind of errors, but everything i found was related to how optionals work (don't know if that's the problem here, but none of them worked), so if anyone knows a solution to this error, i would really appreciate it.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here is the full function where i use it (commented in the lines where the errors appear)</p>
  
  <pre><code>func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
          // Current Cell
          let cell = self.table.dequeueReusableCellWithIdentifier("entry_cell", forIndexPath: indexPath) as EntryTableViewCell
  
          // Current entry
          let entry = entries[indexPath.row]
  
          // Date Formatter
          var formatter = NSDateFormatter()
          formatter.dateStyle = NSDateFormatterStyle.LongStyle
  
          cell.entryTitle.text        = entry.title!
          cell.entryContent.text      = entry.content!
          cell.entryDateLabel.text    = formatter.stringFromDate(entry.createdAt!)
  
          // Try to download image
          let imageURL = ApplicationPreferences.resourcesURLPrefix + entry.picture!
  
          // 1
          if cell.request?.request.URLString != imageURL { // Error: cannot invoke '!=' with an argument list of type '($T6??, String)'
              cell.request?.cancel()
          }
  
          // 2
          if let image = self.imageCache.objectForKey(imageURL) as? UIImage {
              cell.entryImageView.image = image
          } else {
              // 3
              cell.entryImageView.image = nil
  
              // 4
              cell.request = Alamofire.request(.GET, imageURL).validate(contentType: ["image/*"]).responseImage() {
                  (request, _, image, error) in
  
                  if error == nil &amp;&amp; image != nil {
                      // 5
                      self.imageCache.setObject(image!, forKey: request.URLString) // Error: Ambiguous use of 'URLString'
  
                      // 6
                      if request.URLString == cell.request?.request.URLString { // Error: Cannot invoke '==' with an argumet list of type '($T2??, $T8??)'
                          cell.entryImageView.image = image
                      }
                  } else {
                      /*
                      If the cell went off-screen before the image was downloaded, we cancel it and
                      an NSURLErrorDomain (-999: cancelled) is returned. This is a normal behavior.
                      */
                  }
              }
          }
          return cell
  
      }
  </code></pre>
  
  <p>Just in case, the source for that UITableViewCell subclass is:</p>
  
  <pre><code>import UIKit
  import Alamofire
  
  class EntryTableViewCell: UITableViewCell {
  
      @IBOutlet weak var entryImageView: UIImageView!
      @IBOutlet weak var entryTitle: UILabel!
      @IBOutlet weak var entryContent: UILabel!
      @IBOutlet weak var entryDateBackgroundView: UIView!
      @IBOutlet weak var entryDateLabel: UILabel!
  
      var request: Alamofire.Request?
  
      override func awakeFromNib() {
          super.awakeFromNib()
          // Initialization code
      }
  
      override func setSelected(selected: Bool, animated: Bool) {
          super.setSelected(selected, animated: animated)
  
          // Configure the view for the selected state
      }
  
  }
  </code></pre>