Skip to main content

Posts

Showing posts with the label Swift

Swift 6 Concurrency: Handling 'Non-Sendable Type' Errors in @MainActor

  If you have recently enabled Swift 6 language mode or turned on "Strict Concurrency Checking" in Xcode, you have likely encountered the build-breaking wall of red errors. The most persistent among them is usually: "Passing argument of non-sendable type 'X' outside of its actor-isolated context may introduce data races." This error often appears when you attempt to pass a standard class (like a View Model or a data object) into a  Task , or when moving data between background threads and the  @MainActor . In Swift 6, data safety is no longer a suggestion—it is a compiler requirement. This guide breaks down exactly why this error occurs and provides three architectural patterns to resolve it without compromising your app's performance. The Root Cause: Why "Non-Sendable" Matters To fix the error, you must understand the "Isolation Boundary." In the older Grand Central Dispatch (GCD) world, it was the developer's responsibility to e...

Optimizing SwiftUI `Table` Performance for 50,000+ Row Data Grids on macOS

  You have built a native macOS utility using SwiftUI. It looks modern, the code is clean, and it handles test data beautifully. Then you load a real-world dataset—50,000 rows of log entries or financial records—and the application falls apart. Scrolling stutters, the CPU spikes to 100%, and sorting the columns freezes the UI for several seconds. While the older AppKit  NSTableView  handles millions of rows effortlessly using cell recycling and delegation, SwiftUI’s declarative nature introduces a "Diffing Tax" that can cripple performance if not managed correctly. This guide details exactly why SwiftUI  Table  chokes on large datasets and provides a production-ready architectural pattern to render 50k+ rows at 60 FPS. The Root Cause: The SwiftUI Diffing Tax To fix the lag, you must understand what SwiftUI is doing during a render pass. When you pass an array of 50,000 items to a SwiftUI  Table , the framework must determine what changed since the last fram...