It's important to know the difference between static and dynamic dispatch for optimizing the code and better performance.
In this context, dispatching just refers to the action of finding the right function to call.
| import SwiftUI | |
| final class StreamListner { | |
| private let stream: AsyncStream<Int> = AsyncStream<Int> { (continuation) in | |
| Task { | |
| for i in 1...20 { | |
| try? await Task.sleep(for: .seconds(2)) | |
| continuation.yield(i) | |
| } |
| Changes in construction parameters cause the view's body to re-evaluate regardless of that | |
| parameter is using in the body or not. | |
| SwiftUI cannot determine whether this change will cause value of body to change or not, it will blindly re-evalute the body. |
| // | |
| // LegentView.swift | |
| // DifferentSmallTests | |
| // | |
| // Created by Arun's Macbook on 22/01/26. | |
| // | |
| // Support only one line for Legend Text right now. | |
| import SwiftUI |
| // | |
| // SKScene+Edges.swift | |
| // SafeAreaEdges | |
| // | |
| // Created by Arun on 21/12/25. | |
| // | |
| import SpriteKit | |
| // Make sure to access through `viewDidLayoutSubviews` method of ViewController. |
| /* | |
| Displaying a bubble that follows the slider thumb using the `anchorPreference` and | |
| `overlayPreferenceValue` modifiers in SwiftUI. | |
| */ | |
| import SwiftUI | |
| struct OverlayPreferenceKey: PreferenceKey { | |
| typealias Value = Anchor<CGRect>? |
| /* | |
| There is a bug in SwiftUI, some how ignoreSafeArea(.top) don't work when you add PageStyle TabView inside NavigationStack. | |
| This bug is reproduceable in minimum iOS 16.6 | |
| Solution: Just add color to TabView. | |
| */ | |
| struct ContentView: View { | |
| var body: some View { | |
| myTabView |
| import Foundation | |
| import SwiftUI | |
| extension View { | |
| @ViewBuilder | |
| func shimmer(when isLoading: Bool) -> some View { | |
| if isLoading { | |
| self.modifier(Shimmer()) | |
| .redacted(reason: .placeholder) |
| func execute() { | |
| let numberChannel = AsyncChannel<Void>() | |
| let alphabetsChannel = AsyncChannel<Void>() | |
| Task { | |
| var iterator = (1...10).makeIterator() | |
| for await _ in numberChannel { | |
| if let number = iterator.next() { | |
| print(number, terminator: " ") | |
| await alphabetsChannel.send(()) |