Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Massive View Did Load
class ViewController: UITableViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
let currentUser = userManager.loggedInUser()
if let currentUser = currentUser {
var followerPosts = [Post]()
let followers = userManager.followersForUser(currentUser)
for follower in followers {
postManager.fetchPostsForUser(follower) { (posts: [Post]?, error: ErrorType?) -> () in
if let error = error {
self.showAlert(error)
} else if let posts = posts {
followerPosts += posts
}
if follower == followers.last! {
self.recentPosts = Array(followerPosts.sort { $0 > $1 }[0...4])
self.tableView.reloadData()
self.loginButton.hidden = true
}
}
}
} else {
recentPosts =
tableView.reloadData()
loginButton.hidden = false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.