From the course: Complete Guide to SwiftUI

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Swift review: Conditional operators and arrays

Swift review: Conditional operators and arrays

From the course: Complete Guide to SwiftUI

Swift review: Conditional operators and arrays

- [Instructor] If you're relatively new to Swift, there's a few things I'd like to discuss about SwiftUI and Swift, especially if you're coming from UIKit. Unlike UIKit, SwiftUI heavily uses structs instead of classes for user interfaces. There's some behaviors you'll have to get used to with structs if you do everything in classes. More importantly, var in structs works very differently than in classes. As structs are value types, it is more difficult to change values of properties internally with var. You'll find var works a lot more like let than you would expect. On the other hand, the same behavior means init is implicit. Any unassigned declared variable is implicitly a parameter when calling a struct. The body of SwiftUI views is a computed property that returns a view. They do not allow execution of basic Swift code inside the body. While there are places you can use if...else, you'll run into places where even conditional code is hard to add. This is why the conditional…

Contents