Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SWiftUI example
//
// ContentView.swift
//
import AVFoundation
import SwiftUI
struct Track: Identifiable {
var id = UUID()
var title: String
}
let playlist: [Track] = [
Track(title: "Song 1"),
Track(title: "Song 2"),
Track(title: "Song 3"),
]
struct ContentView: View {
@State private var playlistIndex = 0
var body: some View {
VStack {
HStack {
Text("playlistIndex: \(self.playlistIndex)")
}
VStack {
ForEach(0..<playlist.count) {
if $0 == self.playlistIndex {
Text("🔈 \(playlist[$0].title)")
} else {
Text(playlist[$0].title)
}
}
}.padding()
HStack {
Text("").onTapGesture {
if self.playlistIndex == 0 {
self.playlistIndex = playlist.count - 1
} else {
self.playlistIndex = self.playlistIndex - 1
}
}
Text("").onTapGesture {
if self.playlistIndex == playlist.count - 1 {
self.playlistIndex = 0
} else {
self.playlistIndex = self.playlistIndex + 1
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment