I have somehow managed to switch off the error messages that come up as you are typing co9de in, I don't know how I did it, and I can't switch them back on, as they are very useful, please could someone tell me how to switch them back on.
Post
Replies
Boosts
Views
Activity
Is there anyone able to help me worth some Swift coding. I have not done any coding since I was at university over 40 years ago, where I was taught Fortran 77, ICL Assembler and a bit of machine code, and bizarrely
BBC BASIC. The ICL computer filled a six story tower block, and the programs I developed were punched out on punch cards which we handed through a hatch to as technician and we came back a few days later to be told the program had failed at line 10!! my first job, I taught myself Kerningham and Ritchie C. Then I decided I hated coding and concentrated on hardware, networking, servers and systems and later own the internet. So I have not done any coding for5 around 40 years. Now that I have retired I have decided to develop an App to help me3 control my diabetes, so I am trying t5o learn Swift from an online tutorial, so I can’t ask the tutor what I have done wrong. Our second lesson is on functions, and I swear I have copied his code exactly as he had it, but it won’t run and gives the error message:
“Expressions are not allowed at the top level”
I am using an iMac 24-inch M1, running macOS Sonoma 14.2.1 and using Xcode 15.2 I am not sure what version of Swift it is, I assume it is the latest??
This the code ibn total:
import SwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
var amount: Double = 120
var personCount = 2
func calculateATip(amount: Double) {
let tip = amount * 10 / 100
print(tip)
}
calculateATip(amount: 120)
It fails on the last line, what have I done wrong?