loadUserWithID


#1

Could someone please give me an example of how to implement the “loadUserWithID” method in Swift to create an array of tweets for a given user to be displayed in a table view? The Twitter documentation is not detailed enough to explain and I’m sorry but the Cannon Ball app I have been pointed too just has too many controllers and swift files to be able to make sense. It also doesn’t implement that method but instead seems to create an API call looking for hashtags. I am looking for a really simple solution. Below is my current code which simply displays an array of known tweet ID’s as opposed to all those from a single user. I would love if someone could point out how I adapt my code for this. Many thanks in advance.

import UIKit
import TwitterKit

class TwitterViewController: UITableViewController, UITableViewDelegate, UITableViewDataSource, TWTRTweetViewDelegate {
    
    let tweetTableReuseIdentifier = "TweetCell"
    
    var tweets: [TWTRTweet] = [] {
        didSet {
            tableView.reloadData()
        }
    }
    let tweetIDs = ["20", "21", "22", "23", "24"]
    
    override func viewDidLoad() {
   
        Twitter.sharedInstance().logInGuestWithCompletion { guestSession, error in
            if (guestSession != nil) {
                Twitter.sharedInstance().APIClient.loadTweetsWithIDs(self.tweetIDs) { tweets, error in
                    if let ts = tweets as? [TWTRTweet] {
                        self.tweets = ts
                    } else {
                        println("Failed to load tweets: \(error.localizedDescription)")
                    }                    }
        }
        }
    
        // Setup the table view
        tableView.estimatedRowHeight = 150
        tableView.rowHeight = UITableViewAutomaticDimension // Explicitly set on iOS 8 if using automatic row height calculation
        tableView.allowsSelection = false
        tableView.registerClass(TWTRTweetTableViewCell.self, forCellReuseIdentifier: tweetTableReuseIdentifier)
        
                }
    
    
    
    // MARK: UITableViewDelegate Methods
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.tweets.count
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let tweet = tweets[indexPath.row]
        let cell = tableView.dequeueReusableCellWithIdentifier(tweetTableReuseIdentifier, forIndexPath: indexPath) as TWTRTweetTableViewCell
        cell.tweetView.delegate = self
        cell.configureWithTweet(tweet)
        return cell
    }
    
    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        let tweet = tweets[indexPath.row]
        return TWTRTweetTableViewCell.heightForTweet(tweet, width: CGRectGetWidth(self.view.bounds))
    }

}


#2