-
I updated the macOS writer app to publish 25 actual records to CloudKit – and in turn, the iOS reader to fetch this new data. Each record includes a
titleand a remoteimageURL. The titles appear right away, but theAsyncImage(url:)SwiftUI View has some noticeable latency when loading images. Tomorrow I’ll try saving them directly to CloudKit as aCKAssetwhen I create the records and see if this improves performance.Progress is tangible though. This morning the app only displayed temp strings. Tonight it’s showing actual content and it’s starting to feel like a real app.
T minus 57-days…
CloudKit
Sunday July 23, 2023 -
Yesterday I realized my database had duplicate records, and that CloudKit doesn’t support unique constraints. So I added a check to make sure a record doesn’t exist before writing it in. My code evolved into a mix of bits from the documentation and a few phone-a-friends with ChatGPT. It worked. But how?
Today I learned thefetchmethod onCKDatabasetakes in a completion handler as a parameter, which gets called after the operation with the outcome of the fetch. The completion handler itself takes in a singleResultparameter, which is a basic type from the Swift Standard Library.@frozen public enum Result<Success, Failure> where Failure : Error { case success(Success) case failure(Failure) }Notice the
<Success, Failure>in the enum’s declaration. It’s using Swift Generics as a placeholder to represent any Success or Failure value. In CloudKit, these are defined by thefetchmethod to return either a tuple of results, or an error if the request fails. So in the case of.success, I get back an array ofmatchResults. If this array.isEmpty, a write won’t create a duplicate record.CloudKit
Sunday July 23, 2023 -
Sunday July 23, 2023
Taking some time to understand all of yesterday’s code before forging ahead.
-
(1) Made new
CKContainerin the console.
(2) Created macOS app with an iCloud entitlement to the new container.
(3) Inflated the container’s public database with a schema and sample records.
(4) Created separate iOS app with entitlement to same CloudKit container.
(5) FetchedCKRecordobjects from CloudKit and displayed results in SwiftUI.I’ve explored CloudKit as a compliment to Core Data before. But never as a standalone store like this. My main requirement was not using the console for schema and data tasks. I had reluctantly considered
cktoolcli orcktool.jswith some node scripts, but neither of these felt great. A companion Mac app turned out to be a much nicer solution.Seeing the data appear on the iOS app for the first time was a good moment. I didn’t expect to get this far today!
T-minus 58 days…
CloudKit
Saturday July 22, 2023 -
So to prevent writing duplicates into CloudKit, I run this
CKQueryfirst, and if no matches come back, I create a new record.let predicate = NSPredicate(format: "%K == %@", recordField, recordValue) let query = CKQuery(recordType: recordType, predicate: predicate)CloudKit
Saturday July 22, 2023 -
CloudKit doesn’t support unique constraints on schema fields. So running my setup code multiple times led to duplicate records in CloudKit (same data with different UUIDs). So I’m going to try using
CKQueryto make sure a record doesn't already exist before creating it.CloudKit
Saturday July 22, 2023 -
I didn’t see a CloudKit API in Swift to reset the development schema. So I made a SwiftUI button that runs a shell script of
xcrun cktool reset-schema. But I couldn’t get it to work.Error executing command: Error Domain=NSCocoaErrorDomain Code=4 “The file “🧨.sh” doesn’t exist.”
It does exist. But that’s ok. For now, I will click “Reset Environment…” in the CloudKit console and move on with my day.
CloudKit
Saturday July 22, 2023 -
I thought I’d have to define a
CKRecord.RecordTypealong with a schema of field names and types before writing any data into CloudKit. But this is not necessary because a newRecordTypeis automatically created and modeled after the first instance of that particular type to be saved to the database.CloudKit
Saturday July 22, 2023 -
First checkpoint. I have a shell of a Mac app with a CloudKit entitlement. It has a single button that creates a
CKRecordobject and saves it to the container’s public database. And in the CloudKit console, I see the new record type with schema defined along with the sample data!CloudKit
Saturday July 22, 2023 -
I’m breaking ground on a companion Mac app today. It’s main job is to ingest JSON records, transform them to match a CloudKit schema and write them to a public CloudKit database.
And my neighbors are jack hammering their patio, which is bringing some good build something ambiance.CloudKit
Saturday July 22, 2023 -
I’m building a reader app for images. The content is all similar (in the same subject domain) – but coming from multiple sources, each with it’s own schema. Some is available via API, but some is only via data dump.
Phase 1 is defining a common schema, fetching all the data, normalizing it into the shared schema, and then writing it all into a public CloudKit database.T-minus 59 days...
CloudKit
Friday July 21, 2023 -
Friday July 21, 2023
I’ve been a Mac user most of my life. But I've never developed for Apple platforms until now, so I’ve never written any Objective-C. I started learning Swift and SwiftUI last fall. Prior to that, my work revolved around AWS and node.js, so I’ve had to rewire my brain quite a bit.
-
Thursday July 20, 2023
I’m designing and building my first Apple app. My goal is to ship alongside iOS 17 — which given past as prologue, is most likely September 18th.
So I have 60 days to make an app.
-
Thursday July 20, 2023
📍 MOHAI (Museum of History and Industry) — Seattle, WA
-
Wednesday July 19, 2023
I need to learn so many things.
-
Wednesday July 19, 2023
There are always more things.
-
Wednesday July 19, 2023
There are so many things.
-
Wednesday July 19, 2023
I want to make so many things.
-
Thursday July 13, 2023
some pods
-
Tuesday July 11, 2023
Are you reading this or are you hearing this? Is this a transcript of a podcast or a spoken blog post? What is this place?
This is words and sound about making apps with words and sound.