Welcome to another issue!
As you may have noticed, I promote my other iOS Dev Tools Newsletter a lot.
And it worked! Newsletter attracted many subscribers from here. The following of X (ex-Twitter) is growing quickly too.
This led to the creation of a website. It's only a few weeks old, but we have a start. 🤞
My main question is - should I launch a website for this newsletter? Where I can gather the latest news, tools, do interviews, maybe a job section, etc. I'm open to ideas! 💡
Let me hear your thoughts! 👂
I appreciate your support and let's dive into this week's news! 👇
Sponsored Link
RUNWAY
Every mobile release follows the same cycle with the same collection of questions and (often) the same frustrating problems that crop up along the way.
You can resign yourself to wasted time, context switching, and stress. Or you can do the opposite of that. Start by reading our white paper.
Swift Around the Web
Some vs Any
some and any helps to manage type safety in Swift protocols, but they work differently:
- Some keeps things safe: enforces the same type when a function returns different things.
- Any is more flexible: allows different types for functions or collections.
Use some first for safety. Use any with caution when you really need flexibility.
Coding
Memory consumption when loading UIImage from disk
Loading images with UIImage stores them in memory, even if you only use them once. This can use more memory than necessary..
There are two solutions:
- Use UIImage(contentsOfFile:) to avoid caching for quick views.
- Create a custom cache (like with NSCache) for frequently used images to avoid processing them again and again.
The main idea is to be careful about caching images so your SwiftUI app uses memory efficiently.
Using @DebugDescription in Xcode 16
Customizing debug output is essential for understanding complex objects. Xcode 16's @DebugDescription macro simplifies this process.
- CustomDebugStringConvertible: Customize debug descriptions (e.g., Book(title:...)).
- @DebugDescription Macro: Annotate your type with the macro for automatic display in Xcode's inspector.
It helps to provide clearer, faster and more informative debug info without complex commands.
Adding values to the SwiftUI environment with Xcode 16’s Entry macro
Adding custom values to SwiftUI's environment is now much simpler with Xcode 16's @Entry macro.
- Before (@Entry): Define an environment key, default value, getter, and setter. Repetitive and forgettable.
- After (@Entry): Just a single variable with @Entry. Boom, done.
This new syntax eliminates repetitive code and works even for projects targeting older iOS versions.
Apple News
Hello Developer: July 2024
WWDC24 resources are live. Explore new sessions, documentation, and features.
- Events & Learning: Watch sessions, attend online office hours, and browse forums.
- Design Inspiration: Learn design secrets from the Gentler Streak app.
- Skill Up: Access new code samples for multiplatform apps, RealityKit effects, and SwiftUI video experiences.
- Design Guides: Discover best practices for games, Control Center access, and app icons.
- CarPlay Design: Explore the future of CarPlay design systems.
Design
Developing an Infinite Four-Direction Scrollable Pager with SwiftUI
Fatbobman has built a unique scrollable view in SwiftUI that lets you endlessly move in any direction (up, down, left, right). It's more complex than usual scrolling.
This article shows a clever way to do this by ditching regular scrolling and using swipes instead. It also explains how to show multiple views at once to keep things smooth.
By understanding these limitations, the article shows how to find creative solutions and build powerful features within the framework of SwiftUI.
Customizing the appearance of symbol images in SwiftUI
SF Symbols in SwiftUI offer a flexible way to add icons to your app. This article explores various customization options like:
- Size, weight, and color control for better appearance.
- Different color applying options with rendering modes.
- Variable Values for some symbols (e.g., speaker volume).
- Design variations like fill, slash or any shape.
With these customizations, you can create clear and informative icons that enhance your app's design and user experience.
Other Cool Stuff
Xcode-Kotlin 2.0 Release
Big news for Kotlin Multiplatform developers! Xcode-Kotlin 2.0 brings major improvements.
- Up to 5x Faster Debugging: New LLDB script dramatically speeds up variable resolution.
- More Info: See more details about your Kotlin objects directly in Xcode.
- Works Across Languages: Debug Kotlin variables seamlessly within Swift and Objective-C code.
- Built-in Support: List, Map, and more Kotlin types get special handling for clearer insights.
Free, Open Source, and Easy to Install with brew install xcode-kotlin
command.
Show and hide SwiftUI inspectors with an identifiable item
SwiftUI lets you add inspector panels for detailed view information. This article explores a limitation: the inspector modifier currently only accepts a boolean binding for visibility.
To address this, the author proposes a custom inspectorViewModifier that works with optional identifiable items, similar to the sheet modifier. This enhances flexibility and improves developer experience.
Implementing onAppear to Execute Only Once in SwiftUI: Two Approaches
This article shows two ways to run code only once when a SwiftUI view appears for the first time, similar to the viewDidLoad function in UIKit.
- Lazy Property: It only runs the code when it is accessed for the first time.
- State Variable and ViewModifier: Create a reusable modifier to track if the view has appeared first time and only run code then.
Both methods ensure the action runs just once. Choose the method that best suits your needs.
In Case You Missed It
Exploring the Unexplored SwiftUI’s Grid View APIs
SwiftUI lets you create grids of items, like squares in a photo app, etc. There are two ways to do this:
- LazyVGrid/HGrid: Use these for basic grids that change size with your screen.
- Grid/GridRow (iPhone 16 and newer): Build more complex grids with precise control over spacing, alignment, and even merging cells.
For performance-critical grids with large datasets, consider LazyVGrid/HGrid and for table-like layouts with precise control, Grid/GridRow is a powerful option.
Videos
Config 2024: An infinite canvas
Apple's Design Evangelism team has explored designing for Apple Vision Pro, a new platform for spatial computing.
Learn how spatial interfaces create unique user experiences and see inspiring examples from developers. The talk also covers design tools and resources to help you build apps and games for this innovative platform.