View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Vídeos

Abrir menu Fechar menu
  • Coleções
  • Todos os vídeos
  • Sobre

Mais vídeos

  • Sobre
  • Código
  • Swan's Quest, Chapter 3: The notable scroll

    Swift Playgrounds presents "Swan's Quest,” an interactive adventure in four chapters for all ages. Calling all musicians! In this chapter, our Hero has found a mysterious scroll of music, and only you can help decode it. (Don't worry if you can't read music, our clever Lizard is standing by to assist. It's sure to be a note-worthy experience.)

    By learning a little theory, and mastering time to create tones of different lengths, you just might help our Hero face the music… and move onto the next part of their quest.

    Swan's Quest was created for Swift Playgrounds on iPad and Mac, combining frameworks and resources which power the educational experiences in many of our playgrounds, including Sonic Workshop, Sensor Arcade, and Augmented Reality. To learn more about building your own playgrounds, be sure to watch "Create Swift Playgrounds content for iPad and Mac".

    And don't forget to stop by the Developer Forums and share your solution for our side quest.

    Recursos

    • Quest Create playground book
    • Swan's Quest: The notable scroll playground book
      • Vídeo HD
      • Vídeo SD

    Vídeos relacionados

    WWDC20

    • Build a SwiftUI view in Swift Playgrounds
    • Create Swift Playgrounds content for iPad and Mac
    • Swan's Quest, Chapter 1: Voices in the dark
    • Swan's Quest, Chapter 2: A time for tones
    • Swan's Quest, Chapter 4: The sequence completes
  • Buscar neste vídeo...
    • 2:03 - Example Pitch Implementation

      // Example Pitch implementation
      
      public enum Pitch: Double, PitchProtocol {
          case a4 = 440.0
          
          var frequency: Double {
              return self.rawValue
          }
      }
    • 2:09 - NoteProtocol

      // Music.swift
      
      public protocol NoteProtocol {
          
          /// Play this Note through a ToneOutput
          var tone: Tone { get }
          
          /// The duration of this Note as a multiple of quarter notes,
          /// e.g., a half note is 2.0, an eighth note is 0.5
          var length: Float { get }
      }
    • 2:24 - Example Note implementation

      // Example Note implementation
      
      public enum Note: NoteProtocol {
          case quarter(pitch: Pitch)
          
          var tone: Tone {
              switch self {
              case .quarter(let pitch):
                  return Tone(pitch: pitch.frequency, volume: 0.3)
              }
          }
          
          var length: Float {
              switch self {
              case .quarter(_):
                  return 1.0
              }
          }
      }
    • 2:51 - Play more than one tone redux

      // Play more than one tone redux
      
      let toneOutput = ToneOutput()
      let notes = [Note.quarter(pitch: .a4), .half(pitch: .c4), .quarter(pitch: .a4)]
      
      var index = 0
      Timer.scheduledTimer(withTimeInterval: 0.4, repeats: true) { timer in
          guard index < tones.count else {
              timer.invalidate()
              owner.endPerformance()
              return
          }
          
          toneOutput.play(tone: tones[toneIndex].tone)
          index += 1
      }
    • 3:18 - Updating NoteProtocol

      // Music.swift
      
      public protocol NoteProtocol {
          
          /// Play this Note through a ToneOutput
          var tone: Tone { get }
          
          /// The duration of this Note as a multiple of quarter notes,
          /// e.g., a half note is 2.0, an eighth note is 0.5
          var length: Float { get }
      
          /// Length of the smallest Note supported
          static var shortestSupportedNoteLength: Float { get }
      }
    • 3:36 - Updating the Timer interval

      // Play more than one tone redux
      
      let toneOutput = ToneOutput()
      let notes = [Note.quarter(pitch: .a4), .half(pitch: .c4), .quarter(pitch: .a4)]
      var index = 0
      
      let interval = TimeInterval(Note.shortestSupportedNoteLength * 0.5) // 120 BPM
      Timer.scheduledTimer(withTimeInterval: interval, repeats: true) { timer in
          guard index < tones.count else {
              timer.invalidate()
              owner.endPerformance()
              return
          }
          
          toneOutput.play(tone: tones[toneIndex].tone)
          index += 1
      }
    • 4:15 - Adding subdivide to NoteProtocol

      // Music.swift
      
      public protocol NoteProtocol {
          associatedtype PitchType: PitchProtocol
       
          /// Play this Note through a ToneOutput
          var tone: Tone { get }
          
          /// The duration of this Note as a multiple of quarter notes,
          /// e.g., a half note is 2.0, an eighth note is 0.5
          var length: Float { get }
      
          /// Length of the smallest Note supported
          static var shortestSupportedNoteLength: Float { get }
      
          /// Subdivide into a series pitches, according to the shortest
          /// supported note
          func subdivide() -> [PitchType]
      }
    • 4:30 - Putting it all together

      // Play more than one tone redux
          
      let toneOutput = ToneOutput()
      let notes = [Note.quarter(pitch: .a4), .half(pitch: .a4), .quarter(pitch: .a4)]
      var pitches = [Pitch]()
      for note in notes {
          pitches.append(contentsOf: note.subdivide())
      }
      var index = 0
      
      let interval = TimeInterval(Note.shortestSupportedNoteLength * 0.5)
      Timer.scheduledTimer(withTimeInterval: interval, repeats: true) { timer in
          guard index < pitches.count else {
              timer.invalidate()
              owner.endPerformance()
              return
          }
          toneOutput.play(tone: Tone(pitch: pitches[index].frequency, volume: 0.3))
          index += 1
      }

Developer Footer

  • Vídeos
  • WWDC20
  • Swan's Quest, Chapter 3: The notable scroll
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program
    • Mini Apps Partner Program
    • News Partner Program
    • Video Partner Program
    • Security Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines