Creating star ratings

Before we can save the reviews, we need to get all of the data. Getting text from a text field and text view is pretty simple, so we will do that. However, we need a way to let users rate a restaurant by giving it a star rating. The ratings range from 0 to 5 with increments of 0.5. We will use a Picker View to display the stars. Let's get started with this:

  1. Right-click the Model folder in the Review folder and select New File.
  2. Inside of the Choose a template for your new file screen, select iOS at the top and then select Swift File. Then hit Next.
  3. Name this file Rating and hit Create.

Under the import statement, add the following:

enum Rating { case zero case half case one case oneHalf case two case twoHalf case three case threeHalf ...

Get iOS 10 Programming for Beginners 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.