|
Given the following line from the video...
I'm trying to understand what is happening here. I tried using Environment.dismiss() and it would not work.
Coming from C#/Java and trying to sort this out in my head. Thanks guys! |
|
Some of your questions are beyond the knowledge needed for Day 37 lessons. The syntax in the parenthesis is called a key path.
At higher levels of your application, SwiftUI has set up an application-wide structure that provides a ton of piping, bracing, wires, fuse boxes, faucets, and glue to hold your application together. Some of these application-wide variables can be exposed to your application's logic and manipulated. You'll learn about more key path variables in later assignments. The slash-dot syntax allows you to "follow a path" down to the variable that you seek. Here are some made up key paths to illustrate this concept:
You also use key paths in Keep CodingHere's another answer I provided about See -> Find the Key Path |
|
Obelix, Thank you for the response! I did some digging, and found that the dismiss variable I am creating is a DismissAction struct So,
works with my code and verifies the type (If structs are identified just like classes as types). So, a DismissAction struct is gathered into the variable dismiss in the code. DismissAction structs contain one func (according to xCode's reference cited below)
The example of these "Methods with Special Names" that have To clarify, the dismiss variable is a DismissAction struct as far as I can tell, and has but one method: callAsFunction(). The specific So, a question would be: why can the mapped func not directly be called (whatever the actual function is)? I am so confused about why structs (instead of objects), but I suppose I'll learn that later. It seems enormous effort was taken to not use objects. And I am still confused as to what @Environment is. Again, thanks for the response. I have my mind set on understanding SwiftUI. Here's the SwiftUI documentation I found about DismissAction structs:
|
|
But the same syntax is also used to mark Swift macros. (This was introduced in 2023's World WIde Devlopers Conference.) Hold the option key ⌥ whilst hovering over the word Property Wrappers can't be addressed in a forum post. I think there are many online tutorials covering PropertyWrappers in great detail. Hacking With Swift Explanation@twoStraws has some articles. Start here. |
|
Thanks for the help. I marked your answer as the solution. I know much more about Swift digging into this, and look forward to learning about Key Paths, Properties, and Property Wrappers! |
SPONSORED Alex is the iOS & Mac developer’s ultimate AI assistant. It integrates with Xcode, offering a best-in-class Swift coding agent. Generate modern SwiftUI from images. Fast-apply suggestions from Claude 3.5 Sonnet, o3-mini, and DeepSeek R1. Autofix Swift 6 errors and warnings. And so much more. Start your 7-day free trial today!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.