PadCodedocs

Your first app

Build Coffee Counter, a one-screen app with a button that counts, step by step.

You'll build Coffee Counter: a screen that says how many coffees you've had today, and a button that adds one. On the way you'll meet the four things almost every app uses: a variable, views, an action and a formula.

Coffee Counter running in Preview, after two taps: it says Coffees today: 2.

#1. Make the app

  1. On Home, tap New App.
  2. In Name, replace "Untitled App" with Coffee Counter.
  3. In Description, type Counts the coffees I drink. Leave Category as Other.
  4. Tap Create.
The New App sheet, filled in: name Coffee Counter and a description.

The Builder opens on your new app. Its screen already has a big title, "My App", and a line of helper text. Both are ordinary Text views: you can change or delete them later.

The new app open in the Builder, with the Library on the left and the Inspector on the right.

#2. Add a variable to count with

A variable holds a piece of your app's data. This one holds the number of coffees.

  1. In the Library, open the Data & Logic tab: the last of the five icons at the top of the left panel.
  2. Tap Add variable, then Whole Number.

A variable named count appears, starting at 0. A whole number has no decimals, which is right for counting.

Data & Logic with the new variable count: a Whole Number that starts at 0.

#3. Show the count

  1. Open the Components tab: the first icon at the top of the left panel.
  2. Under Text, tap Text. A Text appears under the helper text, already selected.
  3. In the Inspector's Style tab, find Content. Replace its words with Coffees today: {count}.

The braces show a variable's value inside text, so the canvas now reads "Coffees today: 0".

A Text selected on the canvas, showing Coffees today: 0. Its Content is Coffees today: {count}.

#4. Add a button

  1. Under Controls, tap Button. Because the Text is selected, the button goes right below it, and now the button is selected.
  2. In the Inspector, replace the Title with Add a coffee.
The button selected on the canvas, with its Title set to Add a coffee.

#5. Make the button add one

An action is a list of steps that run when something happens. Here, a tap on the button changes count.

  1. With the button selected, open the Inspector's Actions tab. The card at the top says When · Tapped: the steps under it run each time someone taps the button.
  2. Tap Add action. Find Set Value, under Data, or type its name in Search actions, and tap it.
  3. Tap the Set Value step to open its settings.
  4. State is the variable to change. It's already count, your app's only variable. If it isn't, tap it and choose count.
The Actions tab: When Tapped, then a Set Value step whose State is count.
  1. Beside To, tap ⚡︎ (Set from variable) and choose Formula….
  2. Type count + 1. Under it, Right now: 1 shows what the formula works out to on the canvas, where count is 0.
  3. Tap Done.
The formula editor with count + 1 typed in, and Right now: 1 under it.

To now shows the formula. Read the whole step as: "When tapped, set count to count + 1."

The finished step: Set Value, State count, To count + 1.

#6. Try it

  1. Tap Preview in the toolbar. Your app opens on a device.
  2. Tap Add a coffee twice. The text changes to "Coffees today: 2".
  3. Tap Done editing to go back to the Builder.

That's a working app. Each time Preview opens, count starts again at 0. To keep the number after the app closes, have the variable remembered: see Variables.

#Where to go next