# 42 : Experience is a Double-Edged Sword

Published on

Get weekly handpicked updates on Swift and SwiftUI!

Weekly Comment

A few months ago, I was invited to write a SwiftUI tutorial, which included a section on SwiftData. Recently, when I started preparing this content, I found the difficulty far exceeded my expectations. On one hand, I needed to find a way to express concepts suitable for beginners; on the other hand, I needed to break free from the confusion caused by my Core Data experience in understanding and explaining SwiftData.

Indeed, my experience with Core Data has now become a constraint, hindering my ability to analyze and understand SwiftData from a more modern and forward-looking perspective. I’m striving to extract valuable content from historical experience while avoiding its negative impact on understanding new knowledge. There’s been some progress, but it’s not fully there yet.

In Jin Yong’s novel ”The Heaven Sword and Dragon Saber”, Zhang Sanfeng teaches Zhang Wuji his self-created Tai Chi in front of enemies. Only when Zhang Wuji claims to have completely forgotten the routines he just learned does Zhang Sanfeng believe he has understood the true essence of the martial art (mastering the “Way” without being restricted by the “Technique”). Although this is a fictional plot, it reveals a truth: extracting the essence from experience without being bound by it is both important and difficult.

When developers face complex layouts and interactions, if they do not deeply understand SwiftUI’s unique layout logic and internal mechanisms, they may be unable to accurately express their needs through these “simple” APIs. In such cases, some developers might mistakenly think SwiftUI’s capabilities are limited, without realizing that the issue lies in their shallow understanding of the framework.

The above is a passage from my article “Common Misconceptions About SwiftUI”. Some readers strongly opposed this, often those with UIKit programming backgrounds and limited experience with SwiftUI. They believe SwiftUI is no match for UIKit, with many tasks easily accomplished in UIKit being difficult to implement in SwiftUI. Even some developers experienced with other declarative frameworks find their intuition often at odds with SwiftUI’s declarative approach.

I never deny that SwiftUI still has a considerable gap compared to UIKit in terms of feature richness. However, have these developers seriously considered: When learning and using SwiftUI, did they prepare mentally for the shift in thinking? Did they approach SwiftUI with an attitude of accepting and embracing something new? Is your current ‘intuition’ truly innate, or has it been shaped by other experiences?

Experience is crucial for personal growth, but adhering rigidly to it and being constrained by it will actually hinder us from going further. Experience is a double-edged sword; we must wield it to our advantage, not allow it to turn against us.

Originals

Common Misconceptions About SwiftUI

Fatbobman

This article aims to explore several common misconceptions to help developers better understand and utilize SwiftUI. We will dissect these misconceptions, including those about the perceived difficulty of learning SwiftUI, expectations of cross-platform development, the scope of framework capabilities, and misunderstandings about the amount of code involved. By clarifying these concepts, we hope to provide clearer learning directions and usage strategies for SwiftUI developers.

Recent Selections

Magical Particle Effects with SwiftUI Canvas

Pavel Zak

Canvas is a powerful tool in SwiftUI, allowing developers to draw content in a way that is closer to the underlying layer, significantly improving runtime performance. In this article, Pavel Zak demonstrates how to cleverly use SwiftUI’s Canvas view to create stunning magical particle effects. Notably, all the cool visual effects in the article rely entirely on the SwiftUI framework, showcasing not only excellent visual experiences but also ensuring outstanding performance.

Memory Consumption when Loading UIImage from Disk

Antoine van der Lee

Since SwiftUI does not support loading images directly via a path, memory consumption can quickly increase when creating a large number of Image instances. In this article, Antoine van der Lee delves into the issue of memory management when loading images. He thoroughly analyzes several effective optimization strategies: first, considering whether it is truly necessary to store images in memory; then, discussing how to use UIImage(contentsOfFile:) to avoid system caching; and finally, proposing how to implement an efficient image caching mechanism to reduce memory usage. Through rich code examples and performance comparisons, Antoine shows how to strike a good balance between application performance and memory consumption.

Swift VS TypeScript Comparison CheatSheet

Luca Ban

Luca Ban, with years of experience in TypeScript development, recently started using Swift to develop VisionOS applications. He discovered that although TS and Swift share some similarities in concept, in his current projects, he still needed to find more native (Swifty) ways to use the Swift language. Therefore, he created this quick reference to help developers find equivalent methods between the two languages. This cheat sheet details common method comparisons between TypeScript and Swift, helping developers quickly adapt and improve efficiency. The website also welcomes developers to submit Pull Requests to further enrich the content.

Leveling Up SwiftData Error Handling in Xcode Templates

Mike Buss

Although Xcode provides default templates for SwiftData applications, there is still much room for improvement in error handling. Mike Buss proposes a more robust method to handle errors that may occur when creating ModelContainer. Compared to the default template’s approach of using fatalError(), which causes the application to crash, the new method offers a better user experience through state management and custom error views.

The method described in this article is not only applicable to SwiftData but can also be applied to any scenario where errors might occur during application initialization.

Async Await in Swift: The Full Toolkit

Jacob Bartlett

Starting with a common iOS interview question, Jacob Bartlett provides a comprehensive explanation of the core components in Swift’s concurrency toolkit, including async/await, async let, Task, Task group, Actor, MainActor, Sendable, Continuations, AsyncSequence, AsyncStream, and Async Algorithms. For each tool, Jacob not only explains the basic concepts and syntax but also provides practical use cases and code examples, helping readers understand when and where to use these tools most appropriately.

Using @DebugDescription in Xcode 16

Aryaman Sharda

In Swift, the CustomDebugStringConvertible protocol allows developers to customize the way data is described in debug mode to enhance the debugging experience. In this article, Aryaman Sharda introduces the new @DebugDescription macro in Xcode 16, which takes CustomDebugStringConvertible a step further by allowing developers to see custom debug descriptions directly in Xcode’s variable inspector without using print or po commands. The author points out that clear and informative debug output is crucial for understanding code behavior.

Weekly Swift & SwiftUI insights, delivered every Monday night. Join developers worldwide.
Easy unsubscribe, zero spam guaranteed