Can't build project after TwitterKit update

ios

#1

I updated two of my iOS apps to the latest version of TwitterKit using Fabric and the following errors are preventing me from building or running them. Both of these apps were working fine until I completed the update.

For the code straight from the developer documentation, the following error occurs relating to the line - if request != nil {

Binary operator ‘!=’ cannot be applied to operands of type ‘NSURLRequest’ and ‘nil’

This error is also coupled with the following error when retreiving the tweets relating to the tweetIDs - for i in twttrs {

‘[AnyObject]?’ does not have a member named ‘Generator’


#2

Sorted it! Had to update the TwitterKit code to suit the new Swift 2 method for dealing with errors. Annoying that code on twitter implementation page is slow to be updated.


#3

Hey Chater,
Please could you share how you resolved your issues? Im having the same issue regarding the 'Binary operator ‘!=’ cannot be applied to operands of type ‘NSURLRequest’ and ‘nil’, and unsure how to proceed.

Thanks!


#4

The main part of the change to fix this is that Swift 2 uses DO, TRY, CATCH. So instead of checking that the request is nil, you DO the request if it wont be nil, or you TRY the request if there is a possibility of an error. CATCH then handles the error.

Hope this helps you get it working.

This was my code before the update:

func loadTweetIDs() {

    if self.isLoadingTweets {
        println("is loading")
        return
    }
    self.isLoadingTweets = true
    
    let statusesShowEndpoint = "https://api.twitter.com/1.1/statuses/user_timeline.json"
    let params = ["screen_name": "knwApp", "count": "7"]
    var clientError : NSError?
    
    
    
    let request = Twitter.sharedInstance().APIClient.URLRequestWithMethod(
        "GET", URL: statusesShowEndpoint, parameters: params,
        error: &clientError)
    if request != nil {
        
        // Find the Tweet IDs for User
        Twitter.sharedInstance().APIClient.sendTwitterRequest(request) {
            (response, data, connectionError) -> Void in
            if (connectionError == nil) {
                
                var feeddata = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments, error: nil) as! NSArray
                
                var feedcount = feeddata.count
                
                self.tweetIDs.removeAll()
                
                for var i = 0; i < feedcount; i++ {
                    
                    var idNum = feeddata[i].valueForKey("id")!.description as String
                    
                    self.tweetIDs.append(idNum)
                    
                }
                self.loadTweets()
            }
            else {
                println("Error: \(connectionError)")
                self.isLoadingTweets = false
                self.removeImageView()
            }
            
        }
        
    }

Updated my code to this:

func loadTweetIDs() {

    if self.isLoadingTweets {
        print("is loading")
        return
    }
    self.isLoadingTweets = true
    
    let statusesShowEndpoint = "https://api.twitter.com/1.1/statuses/user_timeline.json"
    let params = ["screen_name": "knwApp", "count": "10"]
    var clientError = NSError?()
    
    do {
    let request = Twitter.sharedInstance().APIClient.URLRequestWithMethod("GET", URL: statusesShowEndpoint, parameters: params, error: &clientError)
    
    
        Twitter.sharedInstance().APIClient.sendTwitterRequest(request) {
            (response, data, connectionError) -> Void in
            if (connectionError == nil) {
                
                do {
                
                let feeddata = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) as! NSArray
                
                let feedcount = feeddata.count
                
                self.tweetIDs.removeAll()
                
                for var i = 0; i < feedcount; i++ {
                    
                    let idNum = feeddata[i].valueForKey("id")!.description as String
                    
                    self.tweetIDs.append(idNum)
                    
                }
                self.loadTweets()
                } catch {
                    
                }
            }else {
                print("Error: \(connectionError)")
                self.isLoadingTweets = false
                self.tableView.reloadData()
                self.removeImageView()
            }
        }
        } 
        
    }

#5

will try this out. Thanks! :slight_smile:


#6