---
title: "#36: Today View Widgets 📟"
url: https://littlebitesofcocoa.com/36-today-view-widgets
author: Jake Marsh
date: 2015-07-13
published: 2015-07-13
topics: ["Extensions"]
description: "Creating a Today View Widget for your app is a great way to give users a quick way to access timely information or controls."
---

# #36: Today View Widgets 📟

By Jake Marsh, July 13, 2015. HTML: https://littlebitesofcocoa.com/36-today-view-widgets

Creating a **Today View Widget** for your app is a great way to give users a quick way to access timely information or controls. Let's make one!

## Add the Widget Target

<img src="https://media.littlebitesofcocoa.com/bite-assets/036-today-view-widgets-step-1.png" style="max-width: 172px;" />

## Implement Regular Table View Controller Stuff

``` swift
class TodayViewController: UITableViewController, NCWidgetProviding {
  var bites = [Bite]()

  // not shown here because boring:
  // numberOfRowsInSection returns bites.count
  // cellForRowAtIndexPath just sets cell.textLabel.text = bite.title
}
```

## Conform to NCWidgetProviding Protocol

``` swift
func widgetPerformUpdateWithCompletionHandler(completionHandler: ((NCUpdateResult) -> Void)) {
  Bite.fetchLatest { (bites, error) in
    guard error == nil else { completionHandler(.Failed); return }
    self.bites = bites

      self.tableView?.reloadData()
      self.preferredContentSize = self.tableView!.contentSize

    completionHandler(.NewData)
  }
}
```

## Success!

<img src="https://media.littlebitesofcocoa.com/bite-assets/036-today-view-widgets-sucess.png" style="max-width: 246px;" />
