Thanks, Claude31. This computed variable thing is new to me.
Post
Replies
Boosts
Views
Activity
Are you still experiencing this problem? I know it's been 3 months already, but I'm just curious
You can try downloading the latest beta of Xcode (Xcode 12.2 Beta 2). If that doesn't solve the problem, try building and running the app first, then wait until it finishes building. After the app gets launched in the simulator, close the simulator window and click "resume" on the canvas page.
With $ you access a var that has been declared as @State. With self you access a "basic" var Haha. I can't believe I didn't notice that. Thanks a lot!
@2012jacky, sure.
//
// ContentView.swift
// MinimalisticCalculator
//
// Created by Joe Mama on 10/6/20.
//
import SwiftUI
struct ContentView: View {
@State private var darkMode = false
var body: some View {
ZStack{
if darkMode {
Color.black
.ignoresSafeArea()
} else {
}
VStack{
KeysView()
HStack {
Button(action: {
self.darkMode.toggle()
}) {
if darkMode {
Image(systemName: "moon.fill")
} else {
Image(systemName: "moon")
}
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Thanks, OOPer. Do we know when this update will be released?
I have to build and run it. After that, the canvas works fine.
@OOPer, thank you so much. I found a fix.
ForEach((1...10), id: \.self) {
Text("\($showingSheet)")
}
This doesn't work because showSheet is not in the same struct and also private.
After reading your answer, I changed my code to this:
ForEach(0..<10) {_ in
Text("Hello")
}
The _ in part is required. If I remove that, I'l get an Contextual type for closure argument list expects 1 argument, which cannot be implicitly ignored error.
If I changed (0..<10) to (0...10), I get this error:
Cannot convert value of type 'ClosedRange<Int>' to expected argument type 'Range<Int>'
Thank you so much :D
@OOPer
import SwiftUI
struct ContentView: View {
@State private var showingSheet = false
var body: some View {
ZStack{
VStack{
Text("Reference Buddy :D")
.font(.title)
.fontWeight(.bold)
HStack{
Button("Physics") {
self.showingSheet.toggle()
}
.sheet(isPresented: $showingSheet) {
physicsPage()
}
Button("Trigonometry", action: {})
Button("Calculus", action: {})
}
HStack{
Button("Pre-calculus", action: {})
Button("Geometry", action: {})
Button("Statistics", action: {})
}
HStack{
Button("Chemistry", action: {})
Button("Biology", action: {})
Button("Astronomy", action: {})
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct physicsPage: View {
@Environment(\.presentationMode) var presentationMode
var body: some View {
VStack{
Text("Did you know that...")
ForEach((1...10), id: \.self) {
Text("\($showingSheet)")
}
Button("Back") {
self.presentationMode.wrappedValue.dismiss()
}
}
}
}
Good to know that I'm not the only one that has this problem.
@Claude31, I can, but the nearest authorized Apple service something is too far away. Should I buy a new Mac instead?
Also, Xcode 11 works fine.