Screen · Education

New

Practice

A lesson exercise in chunky word tiles you press into place, with a talking coach, instant feedback and a confetti finish.

A lesson exercise: the coach holds the sentence in a speech bubble, with a hint under every word and a speaker to hear it, and you build the translation from chunky tiles that press down like keys and hop onto the answer line. Check slides up the verdict, with the right answer and the words that differ in bold when you miss, the coach cheering or wincing and a haptic either way, and a combo counts the answers you get right in a row. After the last exercise the lesson ends in confetti, with stars, XP, accuracy and time. Checking is a pure `SentenceCheck` that forgives case and punctuation, and accents when asked, and accepts alternatives.

SwiftUIiOS 17.0+sentence-builder

Get Swift Pieces Pro

$199 once, every piece included. See how installing works · Sign in

01

What's included

SwiftUI source you own, built on Apple frameworks only.

  • Chunky word tiles that press down and hop into the answer line
  • A speech-bubble coach with a hint on every word and the sentence read aloud
  • Check slides up the verdict, with the differing words in bold when you miss
  • A combo for answers in a row, and a confetti finish with stars, XP and accuracy
  • A listening kind, and a pure SentenceCheck you can test

Used in

Language App (template)

02

Implementation notes

How it behaves, what it handles, and the decisions behind it.

The exercise plays like a game you win one sentence at a time. A close key, a chunky progress bar in the unit's color and, from two right answers in a row, a combo flame run across the top. Pip thinks beside a speech bubble that holds the sentence: every word has a dotted line under it, so tap one for its translation, or tap the speaker to hear the whole sentence. The answer is built from tiles that stand on a lip and press down like keys. Tap one and it hops onto the ruled answer lines, leaving a flat ghost so the bank never moves under your thumb; tap it again to send it back. Check slides up the verdict: green with Continue and Pip cheering when you're right, red with the correct answer, the words that differ in bold and Pip wincing when you're not, with a haptic either way. A miss comes back once at the end, and the last exercise ends in confetti, with up to three stars popping in and the lesson's XP, accuracy and time on tiles of their own.

Notes

  • SentenceBuilder(exercises:block:xp:onFinish:) runs a lesson over [SentenceExercise]. Each exercise has its prompt and answer with their languages, distractors mixed into the bank, accepted alternatives, hints for the words of the prompt, the words it teaches and an optional context. The bank's order comes from the exercise's id, so the same exercise always deals the same way.
  • alternatives are other ways to build the answer from the same tiles, such as another word order.
  • kind: .listen hides the sentence: a big speaker key plays it (and plays once on its own), a slow key replays it slower, and you build what you hear.
  • Prompts in a language other than learnerLanguage get a speaker, and so does the correct answer in the verdict. Speech uses AVSpeechSynthesizer at voiceRate; pass onListen to play your own audio. speaksPrompts reads those prompts aloud as each exercise appears.
  • SentenceCheck is pure and tested: check(_:answer:alternatives:options:) returns a SentenceResult with the closest accepted sentence and the words that differ, found by a longest common subsequence. Case, punctuation and spacing never count; accents count unless options.ignoresAccents is on, and ñ always stays ñ.
  • onFinish gets a SentenceLessonResult: the XP (the lesson's xp, plus 5 for a perfect run), 1 to 3 stars from accuracy, the time, the best combo, the exercises missed on the first try and every exercise's words without repeats, ready for a review queue. onProgress reports the share solved after each exercise, to keep a lesson's place when it is closed part way, and SentenceBuilderFinish(result:onContinue:) shows the finish on its own.
  • Keys and tiles are SPTactileStyle from the design system, the coach is SPBuddy and the bursts are SPConfettiBurst, so the screen takes the theme's blocks, type and status colors. A combo of 3, 5 and 10 sets off a small burst by the flame.
  • VoiceOver reads tiles as buttons ("café", "Adds it to your answer"), the answer line as the sentence you've built, and announces the verdict. Tiles grow with Dynamic Type and the page scrolls at the largest sizes.
  • Reduce Motion turns the hop into a fade in place and the springs into short eases, and skips the bursts. Closing part way asks before it discards the lesson.
  • SentenceBuilderExample at the end of SentenceBuilder.swift is the screen in the preview: six exercises at a Spanish café, from ordering to the bill, built both ways and one heard. Copy it as a starting point.