Skip to content

Instantly share code, notes, and snippets.

@rayvinly
Created January 5, 2016 04:43
Show Gist options
  • Save rayvinly/27e1cc51efc3a1015a1e to your computer and use it in GitHub Desktop.
Save rayvinly/27e1cc51efc3a1015a1e to your computer and use it in GitHub Desktop.
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