https://www.swift.org/getting-started/swiftui/
Is there a better tutorial than this one. Can't seem to find a live youtube video that teaches it. I went to git hub and downloaded the source code but all it shows is a big round blue circle. I can't seem to get pass the below code without it giving me an error. I need to see this tutorial live. Any suggestions?
struct ContentView: View {
var activities = ["Archery", "Baseball", "Basketball", "Bowling", "Boxing", "Cricket", "Curling", "Fencing", "Golf", "Hiking", "Lacrosse", "Rugby", "Squash"]
var selected = "Archery"
var body: some View {
// ...
}
}
Post
Replies
Boosts
Views
Activity
I've written the code exactly the way the tutorial explained. Word for word. The tutorial states to write @State var selected = "Bowling" but that doesn't work. I asked for help before but no one replied. So I thought I would post again with the code.
Thanks for zero replies. I can't believe that 28 to 51 people looked at my post and no one responded back. Anyway, I figured it out on my own after taking a break. I was just asking in so many words, where do I put the bold highlighted code.
WHY NOT TRY app completed……….
//
// ContentView.swift
// WhyNotTry
//
// Created by Geraldine Jones on 1/26/24.
//
import SwiftUI
struct ContentView: View {
var activities = ["Archery", "Baseball", "Basketball", "Bowling", "Boxing", "Cricket", "Curling", "Fencing", "Golf", "Hiking", "Lacrosse", "Rugby", "Squash"]
var colors: [Color] = [.blue, .cyan, .gray, .green, .indigo, .mint, .orange, .pink, .purple, .red]
******** @State private var selected = "Baseball"********
@State private var id = 1
var body: some View {
VStack {
Text("Why not try...")
.font(.largeTitle.bold())
VStack {
Circle()
.fill(colors.randomElement() ?? .blue)
.padding()
.overlay(
Image(systemName: "figure.\(selected.lowercased())")
.font(.system(size: 144))
.foregroundColor(.white)
******** .transition(.slide)********
******** .id(id)********
)
Text("\(selected)!")
.font(.title)
}
Spacer()
Button("Try again") {
****** withAnimation(.easeInOut(duration: 1))****** {
selected = activities.randomElement()
?? "Archery"
********id += 1********
}
}
.buttonStyle(.borderedProminent)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Hello,
Is this the proper way to upload my code for developers to view?
struct ContentView: View {
var activities = ["Archery", "Baseball", "Basketball", "Bowling", "Boxing", "Cricket", "Curling", "Fencing", "Golf", "Hiking", "Lacrosse", "Rugby", "Squash"]
var colors: [Color] = [.blue, .cyan, .gray, .green, .indigo, .mint, .orange, .pink, .purple, .red]
@State private var selected = "Baseball"
@State private var id = 1
var body: some View {
VStack {
Text("Why not try...")
.font(.largeTitle.bold())
VStack {
Circle()
.fill(colors.randomElement() ?? .blue)
.padding()
.overlay(
Image(systemName: "figure.\(selected.lowercased())")
.font(.system(size: 144))
.foregroundColor(.white)
.transition(.slide)
.id(id)
)
Text("\(selected)!")
.font(.title)
}
Spacer()
Button("Try again") {
withAnimation(.easeInOut(duration: 1)) {
selected = activities.randomElement()
?? "Archery"
id += 1
}
}
.buttonStyle(.borderedProminent)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}