Use Your Loaf Blog
4 FOLLOWERS
Read regular articles about iOS development, Xcode, Objective-C, Swift, Auto Layout, WWDC, and more. Hi, I am Keith Harrison, I have worked in the software and I.T. services industry for many years. This is the place where I have been writing about my experiences learning and developing for iOS since 2010.
Use Your Loaf Blog
3w ago
Two new sizes as the Pro phones grow in size, and weight, and get even smaller bezels. Here’s what you need to know about the iPhone 16.
The New Models in a Nutshell
As in earlier years, Apple has discontinued the iPhone 15 Pro models and added features to the base iPhone 16 models. Apple also continues to sell the base iPhone 15, iPhone 14, and the iPhone SE.
The Pro models increase in size from last year given us four different screen sizes across the iPhone 16 range:
The base models have the same screen sizes as last years iPhone 15 models, but still lack ProMotion and the Always-on displa ..read more
Use Your Loaf Blog
1M ago
SwiftData gained support for predicate expression in iOS 18. How does it compare to the expressions we can use with Core Data?
Core Data Queries with NSExpression
When Apple launched SwiftData with iOS 17 there were some gaps compared to Core Data. A big one for me was the ability to create an aggregate query (FB12292503). For example, to fetch the minimum, maximum, sum, or average of a property.
I first wrote about using a Core Data expression to query for min and max values back in 2012. Here’s an updated example with a Core Data log entity that contains a set of markers:
public final clas ..read more
Use Your Loaf Blog
1M ago
Apple added the Previewable macro to iOS 18. This generates the boilerplate wrapper view you need to preview a view with State bindings.
What’s The Problem?
I have mixed feelings about SwiftUI previews. When they work they can make creating a view an interactive experience. They can also be slow, break with confusing errors, and need boilerplate container views to create any state bindings.
For that last point consider this form view that expects a binding to a bool:
struct SettingsView: View {
@Binding var showMessages: Bool
var body: some View {
NavigationStack {
Form ..read more
Use Your Loaf Blog
2M ago
Xcode 16 added a property to asset catalogs to opt-out of asset symbol generation. This is especially useful for Swift Packages which had no way to disable the project settings they inherited.
Asset Catalog Symbol Generation - A Recap
Xcode 15 introduced a feature to create Swift, and Objective-C, symbols for colors and images in the asset catalog. Here’s the asset catalog in my main app bundle with the default accent color and app icon, to which I’ve added an image and color:
Using my custom color and image in a SwiftUI view without symbol generation:
VStack {
Image("Star")
Text("Hello ..read more
Use Your Loaf Blog
2M ago
The Entry macro reduces the boilerplate when customizing the SwiftUI environment.
Creating New Environment Values - A Recap
Adding our own values to the SwiftUI environment is a common operation but it requires some boilerplate code each time. See SwiftUI Custom Environment Values for an example but here’s a quick recap:
Create the environment key with a default value:
private struct CaptionColorKey: EnvironmentKey {
static let defaultValue = Color(.secondarySystemBackground)
}
Extend the environment adding a getter/setter for our key:
extension EnvironmentValues {
var captionBack ..read more
Use Your Loaf Blog
2M ago
When Apple launched SwiftData in iOS 17 it was missing the ability to add indexes. Apple corrected that omission in iOS 18.
Core Data Fetch Index
Core Data has long supported adding a fetch index to a property for faster database lookups. For example, if you fetch and sort items by a timestamp you might want to index the timestamp property.
In the Xcode Core Data Model Editor select the entity and then from the Editor use Add Fetch Index. Choose a suitable name for the index, change the property field to the name of the property you want to index and decide if you want ascending or descending ..read more
Use Your Loaf Blog
3M ago
Swift 5.9 introduced a change that allows you to use if and switch statements as expressions. There are some limitations but it can still be useful.
Switch and If Expressions
I feel like I’m late to the party but Swift 5.9 added a useful feature to if and switch statements. If you can stay within some limitations (see below) you can use them as expressions whose value you can return, or assign to a variable.
Here’s an example I had this week. I have an enum modelling the state for a workflow to read, process, and export a file. Some of the states have an associated URL for the input file:
en ..read more
Use Your Loaf Blog
3M ago
Xcode 16 introduces an experimental setting to explicitly build Swift modules. Here’s my notes from trying it out.
What’s The Problem?
When Xcode 15 builds projects it builds modules as the compiler comes across each import statement. This approach of implicitly built modules can block build tasks while they wait for modules they depend on to build.
Xcode 16 introduces an experimental Swift build setting, off by default, to explicitly build modules.
Explicitly Built Modules
To summarise my understanding of how it works:
Xcode scans the project’s source files building a graph of the imported m ..read more
Use Your Loaf Blog
4M ago
My WWDC 2024 viewing guide to help you plan the sessions you want to watch.
Where Do I Start?
The theme for the year is Apple Intelligence. Start by watching the Platforms State of the Union (SOTU) (5 minute recap) for a summary of what’s new this year.
You don’t have to learn everything new today!
There are over 100 sessions and a lot of new stuff to learn. You may feel like you’re getting left behind. Don’t let it overwhelm you. You’ve got time.
The new API’s need iOS 18 and some features are coming later this year. Don’t burn yourself out trying to keep up.
Watching The Sessions
I watch the ..read more
Use Your Loaf Blog
5M ago
Apple added pie charts to SwiftUI in iOS 17. Here’s an example to get you started.
Getting Started
If you’ve already uses the Charts framework to create line, bar, or other types of chart creating a pie chart will look familiar:
Chart {
SectorMark(angle: .value("Red", 0..<10))
.foregroundStyle(.red)
SectorMark(angle: .value("Green", 10..<20))
.foregroundStyle(.green)
SectorMark(angle: .value("Blue", 20..<30))
.foregroundStyle(.blue)
}
The SectorMark, new in iOS 17, is what makes this a pie chart. It has one required parameter the “angle” for each segment of the pi ..read more