Some of you may wonder why I bothered to criticize 🍎 after all they contributed. Could I show the relationship between an App, Scene & View better? I don’t know. But I can try. Let’s begin:
I had a quick fumble after believing I saw something wild, such as:
import SwiftUI
@main
struct SceneStartApp: App {
var body: some Scene {
WindowGroup {
Text("Hello World")
}
}
}
which if you yourself try this will learn that this does not work 😅
Let’s conclude there are no ‘bounds’ for this Text View to be in. Since we cannot define where on the device to show our Text view, the app will crash.
Let us add bounds in our SceneStartApp, and change our Text into a Circle().
import SwiftUI
@main
struct SceneStartApp: App {
var body: some Scene {
WindowGroup {
HStack {
Circle()
Circle()
Circle()
}
}
}
}

Changing the HStack also gave me new alignments, below are VStack & ZStack respectively.


The code for my circles never changed. The ZStack aligns our three circles on top so the user always looks down on them- or the orientation would be deep “inside” the phone, like marbles in the pocket.
One thing we are missing when we do this, is the preview window. I had to run the app 3 times to view what was created, which is not ideal. Let us now remove the three Circle() lines, put ‘ContentView()’ back and add below that line:
ContentView()
.onAppear(perform: {
Task {
let urlString = "https://www.apple.com"
guard let url = URL(string: urlString) else { return }
let urlRequest = URLRequest(url: url)
let (data, response) = try await URLSession.shared.data(for: urlRequest)
print(data)
print(response)
}
})
The line right after ‘ContentView()’ is called a modifier, the contents of which will be run when our ContentView() is ready to appear. Inside the modifier, we create a Task, and inside of this we are creating a url String. We are going to take the String and make it into a URL object. The URL object next becomes a URL Request object. The URLRequest object is then passed to URLSession so we can receive the contents of that request. Finally, our data which is returned can be printed, and the response can be printed further below. The results of the print statements show up when we run the project:
189053 bytes
<NSHTTPURLResponse: 0x600000235300> { URL: https://www.apple.com/ } { Status Code: 200, Headers {
"Cache-Control" = (
"max-age=0"
);
"Content-Encoding" = (
gzip
);
"Content-Length" = (
40058
);
"Content-Type" = (
"text/html; charset=utf-8"
);
Date = (
"Fri, 08 Nov 2024 20:20:38 GMT"
);
Expires = (
"Fri, 08 Nov 2024 20:20:38 GMT"
);
Server = (
Apple
);
"Set-Cookie" = (
"geo=US; path=/; domain=.apple.com"
);
"Strict-Transport-Security" = (
"max-age=31536000; includeSubdomains; preload"
);
Vary = (
"Accept-Encoding"
);
"content-security-policy" = (
"default-src 'self' blob: data: *.akamaized.net *.apple.com *.apple-mapkit.com *.cdn-apple.com *.organicfruitapps.com; child-src blob: mailto: embed.music.apple.com embed.podcasts.apple.com https://recyclingprogram.apple.com swdlp.apple.com www.apple.com www.instagram.com platform.twitter.com www.youtube-nocookie.com; img-src 'unsafe-inline' blob: data: *.apple.com *.apple-mapkit.com *.cdn-apple.com *.mzstatic.com; script-src 'unsafe-inline' 'unsafe-eval' blob: *.apple.com *.apple-mapkit.com www.instagram.com platform.twitter.com; style-src 'unsafe-inline' *.apple.com"
);
"referrer-policy" = (
"no-referrer-when-downgrade"
);
"x-cache" = (
"TCP_MEM_HIT from a23-196-2-157.deploy.akamaitechnologies.com (AkamaiGHost/11.7.0.1-2fb65fbfa7ad4f98bbb706cf20e2b5f6) (-)"
);
"x-content-type-options" = (
nosniff
);
"x-frame-options" = (
SAMEORIGIN
);
"x-xss-protection" = (
"1; mode=block"
);
} }
All this happens when we are loading our ContentView, the system will make our Task go and hit apple.com, and return some information.