#iOSDev tips 9/100
Using protocols for #SwiftUI view models promotes flexibility, modularity, and #testability. By defining a protocol for the view model, you can easily swap implementations for testing or different use cases, ensuring views remain decoupled from specific logic.
#iOSDev tips 8/100
Code coverage in #Xcode measures the percentage of your code executed by tests, helping identify untested parts. Enable it in your scheme settings, and Xcode highlights tested and untested code, guiding you to improve test coverage for better app reliability.
#iOSDev tips 7/100
#SwiftUI animations are easily customized with timing, easing, and spring options. Compose complex animations by chaining modifiers.
Use `.animation()` for timing and effects, and more controls.
#iOSDev tips 6/100
Leverage Swift key paths to access or modify properties dynamically. They enable concise and flexible code, especially for sorting and querying. Key paths are composable and can be chained together, e.g., \Person.address.street.
#SwiftLang
#iOSDev tips 5/100
Custom publishers in Combine are types conforming to Publisher protocol. You can create them by adopting the protocol, defining subscribe method. It emits values, errors, or completion.
#SwiftLang#SwiftUI#Combine
#iOSDev tips 4/100
Use XCTestExpectation for async testing in Swift. Create an expectation, fulfill it in async callbacks, and use wait(for:timeout:) to pause the test until completion. Essential for testing network requests and background operations
#swiftlang
#iOSDev tips 3/100
SwiftUI state mangement
@State: Simple local state management within a view
@Binding: Two-way connection between a state and UI
@ObservedObject: For complex states from external classes conforming to ObservableObject. Views update on published property changes
@EnvironmentObject: For shared data across views, passed implicitly.
@Published: Marks properties in ObservableObject that trigger view updates.
@StateObject: Manages lifecycle of an ObservableObject within a view, for state ownership and initialization.
#SwiftLang#SwiftUI