Swift: Difference between revisions
(Created page with "== Concepts == * @Binding: allows one "source of truth" with many references called bindings * @StateObject: an object owned and mutated by its parent class * Codable: a desig...") |
|||
Line 10: | Line 10: | ||
== Lessons learned == | == Lessons learned == | ||
=== Lists === | |||
* Lists should have NavigationView parents | * Lists should have NavigationView parents | ||
* To avoid the FAT ASSED UGLY NavigationView header in the top navigation view (where you do not WANT it, doh), you have to set this on the EMBEDDED view (not NavigationView): | * To avoid the FAT ASSED UGLY NavigationView header in the top navigation view (where you do not WANT it, doh), you have to set this on the EMBEDDED view (not NavigationView): | ||
.navigationBarHidden(true0 | .navigationBarHidden(true0 | ||
.navigationBarTitle("") // don't skip this or it won't work, DOH | .navigationBarTitle("") // don't skip this or it won't work, DOH | ||
* Always use listStyle plain or you will get awful default Swift 5 LIGHT/DARK backgrounds; it is the only way to set ANY other kind of background on the list | |||
.listStyle(.plain) | |||
== SwiftUI vs UIKit == | == SwiftUI vs UIKit == | ||
UIKit is OLD and BIG. You'll still need it to get to some Apple services until SwiftUI is fully fleshed out. For my JSON API driven apps, I WILL AVOID IT LIKE THE PLAGUE, and hold out for SwiftUI expansion. | UIKit is OLD and BIG. You'll still need it to get to some Apple services until SwiftUI is fully fleshed out. For my JSON API driven apps, I WILL AVOID IT LIKE THE PLAGUE, and hold out for SwiftUI expansion. |
Revision as of 22:53, 25 July 2022
Concepts
- @Binding: allows one "source of truth" with many references called bindings
- @StateObject: an object owned and mutated by its parent class
- Codable: a designation that an object can be en/decoded
- Identifiable: a designation that an object uses predictable identification (eg via an ID)
- Custom modifiers allow you to put all your modifiers (eg .font(.headline)) into one reusable set.
Modifiers vs Custom View
Tip: Often folks wonder when it’s better to add a custom view modifier versus just adding a new method to View, and really it comes down to one main reason: custom view modifiers can have their own stored properties, whereas extensions to View cannot.
Lessons learned
Lists
- Lists should have NavigationView parents
- To avoid the FAT ASSED UGLY NavigationView header in the top navigation view (where you do not WANT it, doh), you have to set this on the EMBEDDED view (not NavigationView):
.navigationBarHidden(true0 .navigationBarTitle("") // don't skip this or it won't work, DOH
- Always use listStyle plain or you will get awful default Swift 5 LIGHT/DARK backgrounds; it is the only way to set ANY other kind of background on the list
.listStyle(.plain)
SwiftUI vs UIKit
UIKit is OLD and BIG. You'll still need it to get to some Apple services until SwiftUI is fully fleshed out. For my JSON API driven apps, I WILL AVOID IT LIKE THE PLAGUE, and hold out for SwiftUI expansion.