Sponsored Link
Webinar: Introducing a Market-Changing Approach to Mobile App Security
Join Guardsquare to learn more about our new guided configuration approach to mobile application protection. Our latest innovation ensures that all developers, regardless of their security knowledge, can effortlessly launch apps with industry-leading protection - in less than a day.
Swift Around the Web
Extending Optionals in Swift
Swift
allows you to extend optional types to add custom properties and methods. This lets you check for nil
or empty values directly on optional strings. This technique can be applied to other optional types to add custom functionality, making your code more concise and readable.
Reinventing Core Data Development with SwiftData Principles
Leverage SwiftData's modern approach to improve Core Data development. Fatbobman has explored how to apply SwiftData's principles to Core Data, focusing on data modeling, concurrency, and testing.
By adopting these principles, you can create more efficient, reliable, and maintainable Core Data applications. While SwiftData offers a more modern approach, Core Data remains a robust option for many projects.
Coding
Introducing Swift Testing. Basics.
Swift Testing is a new framework that simplifies testing in Swift. It introduces expressive macros like @Test
and #expect
to write concise and readable tests.
This framework allows you to write more effective and maintainable tests for your Swift projects. It integrates seamlessly with Xcode, providing a rich testing experience.
Building a Customizable Segmented Control in SwiftUI
Create a custom SegmentedControl in SwiftUI for more flexibility and control over design and functionality. This guide demonstrates how to implement a segmented control with dynamic options, theme integration, and interactive feedback. By leveraging SwiftUI's features, you can create visually appealing and user-friendly segmented controls.
visionOS
Positioning volumes in space in a VisionOS app
Explore VisionOS 2.0's new APIs to create immersive volumetric experiences. By using the onVolumeViewpointChange
modifier, you can dynamically adjust the orientation of volumetric objects to always face the user.
Experiment with different rotation strategies, such as slerp, to achieve smooth and natural transitions. Additionally, you can control the frequency of updates by setting the updateStrategy
parameter.
Apple News
Apple Push Notification service server certificate update
Apple is updating its Push Notification service (APNs) server certificates. To ensure continuous push notification delivery, developers need to update their application's Trust Store with the new SHA-2 Root: USERTrust RSA Certification Authority certificate.
This update is mandatory for both sandbox and production environments. It's crucial to include both old and new certificates to avoid service interruptions during the transition period.
Design
Buggy linear gradients in SwiftUI Charts
SwiftUI's Charts framework can exhibit unexpected behavior when using linear gradients with very small color stop deltas. To achieve hard stops in gradients, it's necessary to ensure a minimum delta of 0.0001 between color stops. This workaround prevents unintended blending and ensures accurate color transitions.
Other Cool Stuff
Slow incremental builds using xcodebuild
xcodebuild is significantly slower than Xcode for incremental builds due to unnecessary network requests to Apple's developer services API. This issue can be mitigated by temporarily blocking the domain.
However, this workaround might disable some Xcode features. Apple has been informed of the issue, and a fix is awaited. A plugin for Neovim automates the workaround process.
Beware UserDefaults: a tale of hard-to-find bugs, and lost data
There is a potential issue with UserDefaults
on iOS: it can become unavailable due to device encryption. This can lead to data loss or unexpected app behavior.
The post suggests two solutions: use notification to wait for protected data availability and Implement a custom storage solution using a non-encrypted file in the app's container directory.
For a more robust and convenient approach, the author recommends using the TinyStorage
library.
In Case You Missed It
How to keep Dateβs microseconds precision in Swift
This Swift guide addresses an issue with ISO8601DateFormatter
. While it parses ISO8601 formatted dates, it loses microsecond precision. This can lead to incorrect sorting when using dates for that purpose.
The solution involves creating a custom method for ISO8601DateFormatter
that extracts microseconds from the string, incorporates them into the parsed date, and ensures accurate dates with microsecond details for tasks like sorting.
SwiftData Modularization with TCA in Tuist
Leverage SwiftData, TCA, and Tuist to modularize your iOS project. By creating separate modules for Core, Repository, Shared, and Stores we can configure Tuist workspaces, manage dependencies, and make types public.
Learn the efficient use of DependencyKey
and ModelContainer
for dependency management and ensuring correct module dependencies. This approach leads to a cleaner, more maintainable, and scalable project.
Tutorials
Comprehensive Guide to Mastering KeyPath in Swift
Another great guide by Fatbobman on the KeyPath feature of Swift for referencing properties within a type. It provides a type-safe and flexible way to access and manipulate properties within a type.
This powerful feature enhances code clarity and maintainability, especially when dealing with nested properties and generic data structures. By understanding KeyPath's concepts and applications, you can write more concise and efficient Swift code.
Sparkling shiny things with Metal and SwiftUI
Build interactive and visually stunning user interfaces using SwiftUI and Metal shaders. Learn how to implement effects like glowing borders, rippling waves, and particle clouds.
This guide provides step-by-step instructions and code examples to help you master these techniques. By combining SwiftUI and Metal, you can create dynamic and captivating user interfaces.
Videos
DebugDescription Macro
Stewart Lynch explained the new DebugDescription macro introduced in Xcode 16, simplifying the process of debugging in iOS, iPadOS, macOS, and other Xcode projects.
By replacing the CustomDebugStringConvertible
protocol, this macro provides a cleaner and more efficient way to customize the output in the debugger. It also highlights the differences in console output compared to the traditional approach.