Some learning notes about UIKit, Swift, SwiftUI and Objective-C.
Basics
- OOP
Project Structure
|
|
@State & @Binding
$ symbol
- Binding
- e.g. in actionSheet, using $variable allows actionSheet update its value instead of solely reading its value
@State
- Creates pointer in memory, not necessarily making variable mutable
- Views that listen to the @State variable will auto change their presentations according to the variable
|
|
@Binding
- Require caller to pass in a $Variable Normal usage
|
|
With Object
|
|
ForEach
The target should contain identifiable “unique” items (String normally considered as not identifiable, since two string might look the same but are used to identify different stuff)
To force foreach to think each the element are identifiable
|
|
Different ForEach list method
Assume there is a list:
|
|
From 0 to end of list
|
|
For indices
|
|
For all items in the list
|
|
Normal number for each
|
|
Remark:
- Swift uses three dots “…” instead of “..”
Symbols & Icons
Download SF symbols Sample usage:
|
|
Factoring out bricks
a. New VIEW struct b. Var some view
Grid
LazyVGrid (Makes as small as possible to fit more) Other stacks (Use up all available spaces)
Other
To take all open space available that no one want
|
|
Aspect ratio
|
|
Classes and Structures
Class
|
|
Output -> Boeing
Structure
|
|
Output -> Airbus
New struct
Similar to what Java does
1. Create new struct (better in new Swift file)
|
|
2. Initialize
In normal case
|
|
If the struct needs to have $Variable, a list of it will be:
|
|
Comment
Standard comment
|
|
To create sections in code
|
|