Skip to content

elf0-fr/XylophoneSwiftUI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

XylophoneSwiftUI

This project is a modern reimagining of the sample code from “The Complete iOS Development Bootcamp”, rebuilt entirely using SwiftUI. But this is more than a UIKit-to-SwiftUI migration — it also includes an interactive WidgetKit extension and AppIntents integration to support Siri and the Shortcuts app.

What’s New Compared to the Original?

  • Fully rewritten using SwiftUI, leveraging modern, declarative UI design.
  • Integrated interactive widget with WidgetKit, allowing quick user interactions directly from the home screen.
  • AppIntent integration to trigger actions via Siri voice commands or the Shortcuts app.
  • Updated to support the latest versions of iOS (18) and Xcode (16).

SwiftUI

Portrait Landscape
struct ContentView: View {
    
    let spacing: CGFloat = 8
    
    var body: some View {
        GeometryReader { geometry in
            VStack(spacing: spacing) {
                Group(subviews: musicalNotes) { subviews in
                    ForEach(subviews.indices, id: \.self) { index in
                        subviews[index]
                            .padding(.horizontal, getPadding(forIndex: index))
                    }
                    .frame(
                        height: getHeight(
                            withSubviewsCount: subviews.count,
                            geometry: geometry
                        )
                    )
                }
            }
        }
    }
    
    @ViewBuilder
    var musicalNotes: some View {
        MusicalNote(note: "C", color: .red)
        MusicalNote(note: "D", color: .orange)
        MusicalNote(note: "E", color: .yellow)
        MusicalNote(note: "F", color: .green)
        MusicalNote(note: "G", color: .indigo)
        MusicalNote(note: "A", color: .blue)
        MusicalNote(note: "B", color: .purple)
    }
    
    func getHeight(withSubviewsCount count: Int, geometry: GeometryProxy) -> CGFloat {
        let availableSpace = geometry.size.height - spacing * CGFloat(count - 1)
        
        return availableSpace / CGFloat(count)
    }
    
    func getPadding(forIndex index: Int) -> CGFloat {
        return CGFloat(index * 8)
    }
}

Widget

Widget

AppIntent

Shortcut

About

The SwiftUI version of Dr. Angela Yu's application for The Complete iOS App Development Bootcamp

Topics

Resources

Stars

Watchers

Forks

Languages