Now that we have permission, we need to set up notifications. We will start setting up our buttons:
- Open the RestaurantDetailViewController.swift file.
- At the top of the file, under import UIKit, add the following:
import UserNotifications
- Add the following method after our @IBAction func unwindReviewCancel(segue: UIStoryboardSegue) {} method and before the last curly bracket of our class file:
@IBAction func onTimeTapped(sender: UIButton) {
}
- Save the file, and you will see an empty circle appear next to this new @IBAction.
- Open the RestaurantDetail.storyboard for which we are going to use the time buttons for our notifications. Select each button. In the Attributes inspector, update the text inside of eachbutton to display 9:30pm, 10:00pm, and 10:30pm. You should get the following:
- Select RestaurantDetailViewController and then select the Connections inspector in the Utilities panel. Under Received Actions, you should see onTimeTappedWithSender, which we added earlier:
![](assets/6c67bc25-ae90-4a55-b0cd-af200fdc409a.png)
- Click and drag from the empty circle next to onTimeTappedWithSender to the first button (marked 9:30pm) in the restaurant detail scene:
![](assets/c7e825d8-dbf9-4265-8217-762b799c7174.png)
- In the prompt, select Touch Up Inside:
![](assets/4165ef6b-fdc9-4ca7-83dd-d17904b11a13.png)
- Repeat these steps for the remaining two buttons (10:00pm and 10:30pm), clicking and dragging the same circle (now filled) to each of the remaining buttons in the scene and then choosing Touch Up Inside for each prompt that follows.
- Open RestaurantDetailViewController.swift; this is where we need to get the time from inside of the buttons and pass them to our notifications. Add the following method after the onTimeTapped() method:
func showNotification(sender:String?) {
print(sender as Any)
}
- Inside of the onTimeTapped() method, add the following:
showNotification(sender: sender.titleLabel?.text)
We are now passing the time value to our showNotification() method. Build and run the project by hitting the Play button (or using command + R). You should now see the time of each selected button in the console.