Coding the Action

Now that we’ve added a button to our view and wired it up, we can run the app again. We can tap the Play button, but it doesn’t do anything. Did we set up our connection correctly? One thing we can do as a sanity check is to log a message to make sure our code is really running. Once that’s verified, we can move on to implementing our player functionality.


Back in Chapter 2, we learned about the print function for logging messages to the Xcode console. We can use that in our action to just log a message every time the button is tapped, and thereby verify that the connections are working. Select ViewController.swift in the Project Navigator (1) to edit its source code and rewrite handlePlayPauseTapped like this:

Get iOS 10 SDK Development, 1st Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.