Skip to content

Instantly share code, notes, and snippets.

@donnywals
Last active August 29, 2015 14:26
Show Gist options
  • Save donnywals/45041430e030ef17c88e to your computer and use it in GitHub Desktop.
Save donnywals/45041430e030ef17c88e to your computer and use it in GitHub Desktop.
class MainViewController: UIViewController() {
var viewModel = WebsiteList()
func tabsButtonPressed() {
let vc = ListView(vm: viewModel)
// present the vc
}
}
class ListView: UIViewController {
var viewModel: WebsiteList
@IBOutlet collectionView: UICollectionView!
convenience init(vm: WebsiteList) {
viewModel = vm
}
override func viewDidLoad() {
collectionView.dataSource = self
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("myCell", forIndexPath: indexPath) as! MyCell
cell.image = viewModel.imageForIndexPath(indexPath)
return cell
}
}
struct WebsiteList {
var images: [UIImage] = [UIImage]()
func addImage(image: UIImage) {
images.append(image)
}
func imageForIndexPath(indexPath: NSIndexPath) -> UIImage {
return images[indexPath.row]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment