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()
}
}
}
}