How I Built Baby Tracker

Baby Tracker Pro started because my son was born and every tracking app I tried annoyed me. Some were full of ads. Others wanted six taps to log a diaper. The one thing I really needed was for my wife, our nanny, and me to see the same data, so that when the pediatrician asked how often he was eating, I had an actual answer. Huckleberry wasn't really a thing then, but it was for my second born. That being said, it offered a LOT of things and I just wanted to keep it simple still. Opening up Huckleberry for the first time is daunting. Baby Tracker Pro tries to not be.

Anyways that was July 2022. The repo is now 208 commits on main, about 22,600 lines of Swift across 111 files, an iOS app, and a widget extension. Like I did with Card of War, I ran git log --reverse and read the whole thing top to bottom. The commits split cleanly by year:

   26 2022
  63 2025
 119 2026

There's no 2023 or 2024 in that list. Because it was doing everything I wanted it to.

Timeline

Here's the short version before we get into the details.

  • Jul 17, 2022: Initial Commit. The Xcode Core Data + CloudKit template, one Item entity with a timestamp.
  • Aug 26, 2022: StoreKit code and the CloudKit deduplication logic land in the same commit, titled Upates.
  • Sep 18, 2022: Family sharing over CKShare. The commit is titled Rocking and rolling.
  • Sep 26, 2022: A JSON importer so I could bring over months of data from the app we used before. And import test data.
  • Oct 2022: Charts, purchases, and an App Store review fix (updates for apple). Then nothing for 27 months.
  • Jan 2025: Growth tracking and onboarding.
  • Mar 2025: Siri Shortcuts.
  • Sep 2025: A GitHub Action that bumps the version every Monday.
  • Nov 2025: A crash audit, smart notifications, Home Screen widgets, and version 2.0.
  • Jan 2026: Free tier limits, grandfathering for existing users, and a commit that fixes "33+ bugs".
  • May 2026: Spanish and French translations, milestones, and sleep Live Activities.
  • Jun 2026: The busiest month. Custom event types, three home screen layouts, detailed diaper logging, a 24-hour report, and a lot of sharing fixes. Second son is born.
  • Jul to Aug 2026: A fight with subscription lapses and family shares, then a reversal.
  • Aug 2026: I nearly replaced CloudKit sync with my own server.
  • Sep 2026: Pro stays unlocked from a cached entitlement while StoreKit catches up.

2022: the template and two SQLite files

The first commit is exactly what Xcode gives you when you check "Use Core Data" and "Host in CloudKit":

<entity name="Item" representedClassName="Item" syncable="YES" codeGenerationType="class">
    <attribute name="timestamp" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
</entity>

Item became TrackedEvent, and Child showed up to own those events. The important decision in 2022 was the one I didn't fully understand at the time: sharing a baby with another iCloud user means two stores. Your own babies live in the CloudKit private database. Babies someone shared with you live in the shared database. NSPersistentCloudKitContainer can mirror both, but you have to set it up yourself:

let container = NSPersistentCloudKitContainer(name: containerName)

guard let privateStoreDescription = container.persistentStoreDescriptions.first else {
    fatalError("Failed to retrieve a persistent store description")
}
privateStoreDescription.url = privateStoreFolderURL.appendingPathComponent("private.sqlite")
privateStoreDescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
privateStoreDescription.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)

let privateOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: gCloudKitContainerIdentifier)
privateOptions.databaseScope = .private
privateStoreDescription.cloudKitContainerOptions = privateOptions

// A second store, mirrored to the CloudKit shared database.
guard let sharedStoreDescription = privateStoreDescription.copy() as? NSPersistentStoreDescription else {
    fatalError("Copying the private store description returned an unexpected value")
}
sharedStoreDescription.url = sharedStoreFolderURL.appendingPathComponent("shared.sqlite")

let sharedOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: gCloudKitContainerIdentifier)
sharedOptions.databaseScope = .shared
sharedStoreDescription.cloudKitContainerOptions = sharedOptions

container.persistentStoreDescriptions.append(sharedStoreDescription)

Persistent history tracking is on for both stores because CloudKit sync can and will produce duplicates. Two devices can each create the same Child while offline, and once both sync you have two copies. The fix is a deduplication pass that runs over new history transactions. It picks a deterministic winner among children with the same UUID in the same record zone, then moves every event from the losers over to the winner:

let tagZoneID = persistentContainer.recordID(for: child.objectID)?.zoneID
duplicatedChildren = duplicatedChildren.filter {
    self.persistentContainer.recordID(for: $0.objectID)?.zoneID == tagZoneID
}

guard duplicatedChildren.count > 1, let winner = duplicatedChildren.first else {
    return
}
duplicatedChildren.removeFirst()

for duplicatedChild in duplicatedChildren {
    if let childSet = duplicatedChild.events {
        for case let childEvent as TrackedEvent in childSet {
            duplicatedChild.removeFromEvents(childEvent)
            winner.addToEvents(childEvent)
        }
    }
    context.delete(duplicatedChild)
}

If you've read Apple's "Sharing Core Data objects between iCloud users" sample, this will look familiar. The variable is still called tagZoneID and the comments still talk about tags and photos, because that's where I started. Since every peer sorts the same way and picks the same winner, all devices converge without talking to each other. That property matters a lot more than it looks like it should.

Sharing itself is a single call. UICloudSharingController takes a closure that creates the share, and the container does the heavy lifting:

controller = UICloudSharingController { _, completion in
    PersistenceController.shared.persistentContainer.share([child], to: nil) { _, share, ckContainer, error in
        if let share, let context = child.managedObjectContext {
            context.performAndWait {
                share[CKShare.SystemFieldKey.title] = title
            }
        }
        completion(share, ckContainer, error)
    }
}

The last piece from 2022 is boring and I'm still glad I did it. I used quicktype to generate Codable types from the old app's JSON export, and I wrote an importer. On day one, the app had months of real history in it, which made charts and stats useful right away.

Then I shipped it in October, it did what I needed, and I stopped touching it.

The 27-month gap

From October 2022 to January 2025, the repo has zero commits. The app kept running and the CloudKit sync kept syncing. I think this is the real argument for the CloudKit route. There was no server to keep alive and nothing to pay for beyond the developer account. For a solo developer with a toddler, that was exactly the right trade.

When I came back in January 2025, it was to add growth tracking (weight, height, head circumference) and an onboarding flow. Siri Shortcuts followed in March. The commit messages from this stretch are updates, fixes, working, and one Changes and fixes, lets gooo. Nobody was going to git blame any of it. Except myself for this article, haha.

Late 2025: making it a real product

September 2025 is when the project starts acting like a product. The first change wasn't a feature. It was a GitHub Action that runs every Monday at 9:00 UTC, bumps the patch version, tags it, and creates a release:

on:
  schedule:
    # Runs every Monday at 9:00 AM UTC
    - cron: '0 9 * * 1'
  workflow_dispatch:

Half the commits in the log after this point are chore: bump version to 2.x.y [skip ci]. That looks like noise, but it gave me a heartbeat. Every week there was a version number to ship against, and if I hadn't touched anything, the bot still had. I wrote more about this pattern in release management with GitHub Actions.

November 2025 brought the first serious cleanup. I wrote a FEATURE_ROADMAP.md and a TASKLIST.md broken into phases, and the commit messages change overnight from updates to fix: replace force unwrapping with safe error handling in DataTypes.swift. Phase 1.1 was a crash audit: force unwraps in date parsing, fatalError calls in store setup, and nil dereferences in the card views. Phase 2.1 added smart notifications. Phase 6.4 added Home Screen widgets, which meant an App Group and a WidgetDataManager that writes a snapshot the widget extension can read without touching Core Data. The release that came out of that month was 2.0, and the diff from the end of 1.x was 42 files, 5,500 lines in and 2,000 out.

January 2026: the free tier

For three years the app was mostly free with a Pro unlock. In January I added actual limits for new users: 20 events per day and 7 days of visible history. Medicine and temperature cards appear with a lock on them. Stats show up blurred.

The tricky part was not punishing anyone who had been using the app for years. The app had never recorded when a child was created, so I had no date to compare against. I added a createdAt attribute to Child anyway, and the trick is that it starts out empty. When you add a new optional attribute, Core Data's lightweight migration leaves it nil on every existing row. From that release on, saving a new child stamps it:

childToSave.createdAt = childToSave.createdAt ?? Date()

After the update, a nil means "this child existed before the limits shipped." The legacy check is mostly that one guard:

var isLegacyUser: Bool {
    let legacyCutoffDate = ISO8601DateFormatter().date(from: "2025-02-01T00:00:00Z") ?? Date.distantPast

    let request = Child.fetchRequest()
    let allChildren = (try? stack.persistentContainer.viewContext.fetch(request)) ?? []

    for child in allChildren {
        // No createdAt means the child existed before the update.
        guard let createdAt = child.createdAt else {
            return true
        }
        if createdAt < legacyCutoffDate {
            return true
        }
    }
    return false
}

I never had to look back through old data to find existing users. The schema change marked them for me.

The cutoff date turns out to be decoration. Every child made before the update has nil, and every child made after it gets a 2026 date, so the comparison never returns true. The nil does all the work.

While writing this post, I also found a bug in that first snippet. The same addChild function handles edits, so renaming an existing child runs ?? Date() and stamps today's date into the empty field. A grandfathered user with one child who fixes a typo in the name stops being a legacy user. The fix is to set createdAt only on the create path. If nil carries meaning in your model, make sure nothing fills it in by accident.

Adding the attribute with CloudKit also meant running initializeCloudKitSchema() against the development container so the new field existed in the schema before I promoted it to production. I keep a separate InitializeCloudKitSchema target that compiles only the model and persistence code with a flag set, so I can't accidentally ship that call:

#if InitializeCloudKitSchema
    do {
        try container.initializeCloudKitSchema()
    } catch {
        print("\(#function): initializeCloudKitSchema: \(error)")
    }
#else
container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
container.viewContext.transactionAuthor = TransactionAuthor.app
container.viewContext.automaticallyMergesChangesFromParent = true
#endif

The same commit fixed 33 bugs, and one of them is worth calling out. The deduplication predicate compared objectID against a child's id. Those are never equal, so dedup silently did nothing for some unknown period of time. I found it during a full audit with Claude Code, which is also roughly when Claude starts showing up as a co-author in the log: one commit in January, 44 in June, 29 in August.

Spring 2026: Live Activities

Sleep and breastfeeding are timed events, and the obvious place for a running timer is the Lock Screen. Live Activities landed in May. The first bug report came in June: a sleep Live Activity that stayed on the Lock Screen after the sleep had ended.

The cause was a classic one. I was keying my dictionary by activity.id, which is ActivityKit's own identifier, and then looking it up with the event's UUID. Those never match. After an app relaunch, end(eventID:) couldn't find anything and the activity lived forever. The fix stores the event UUID in the attributes, rebuilds the map from Activity.activities on launch, and reconciles against the set of events that are actually in progress:

func reconcile(activeEventIDs: Set<UUID>) {
    for activity in Activity<TrackingActivityAttributes>.activities {
        if let eventID = activity.attributes.eventID, activeEventIDs.contains(eventID) {
            activities[eventID] = activity
        } else {
            Task { await activity.end(nil, dismissalPolicy: .immediate) }
            if let eventID = activity.attributes.eventID {
                activities[eventID] = nil
            }
        }
    }
}

Activities created by older versions have no eventID, so they're always treated as stale. If you ever ship a Live Activity, put your own identifier in the attributes from day one and write a reconcile function. The app will get killed mid-nap, so plan for it.

June 2026: features, and sharing bugs everywhere

June is the busiest month in the log by a wide margin. This is when the repo starts using pull requests, and the numbered PRs tell the story: custom event types (#3), manual feeding amounts (#4), diaper amount and poo type and color (#6), and a Last 24 Hours report (#8). Custom events were the big one. Each CustomEventType belongs to a child and has an ordered list of fields with a kind of number, text, options, or toggle. An event stores its values keyed by field UUID, so the type can change without breaking older events.

The rest of June was sharing. Participants didn't always see a shared baby (#2). Creating a share link failed in some cases (#7). The share sheet reported a save error that wasn't real (#9), and it showed up blank the first time you opened it (#10). That last one I fixed by presenting UICloudSharingController through UIKit directly instead of wrapping it in a SwiftUI sheet. UICloudSharingController.delegate is weak, too, so the coordinator needs something to keep it alive:

objc_setAssociatedObject(controller, &CloudSharingCoordinator.associatedObjectKey,
                         coordinator, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)

July and August: the subscription lapse that went in a circle

This is the part of the log I'm least proud of and learned the most from.

Sharing is a Pro feature, so in June (#12) I added the obvious rule: when Pro lapses, revoke every share you own. The owner keeps their data in the private store, and participants see a "Sharing Ended" notice. The implementation deleted each owned CKShare with a CKModifyRecordsOperation.

A month later I found a hole (#14). Pro can come through Apple Family Sharing, so a share owner might never have bought anything. My lapse detection looked at the device's own purchase history, so those owners resolved to "unknown" and were never revoked. Worse, if the purchaser and the share owner were different people, the purchaser's lapse revoked nothing because they owned no shares. The fix re-keyed revocation on an invariant: a share may exist only while the owner's device holds an active entitlement from any source. Transaction.currentEntitlements includes family-shared subscriptions, so that became the signal. Because StoreKit can briefly report nothing during a cold launch, the check re-runs about six times over 18 seconds and aborts as soon as the entitlement comes back.

Then in August (#20), I removed the whole thing and preserved family shares after Pro lapses.

I'd spent two PRs making revocation correct, and the right answer was not to revoke at all. Picture a parent whose card expires at 2am, and the nanny's phone loses the baby's feeding history in the middle of a shift. No conversion rate makes that worth it. Sometimes the bug is the policy, and the code was fine.

The last piece of this saga landed in September. hasPro needed the product catalog to load over the network before it could return true, so entitled users saw Pro features locked for a few seconds on every launch, or forever when offline. The fix caches the last verified result and treats it as optimistic:

/// Whether the user is entitled to Pro right now.
public var hasPro: Bool {
    hasVerifiedEntitlement || cachedHasPro
}

/// Persist the outcome of a completed entitlement check. Call only after a check
/// has fully resolved, so a transient "nothing yet" never revokes Pro.
private func commitVerifiedEntitlementToCache() {
    let verified = hasVerifiedEntitlement
    guard verified != cachedHasPro else { return }
    cachedHasPro = verified
    defaults.set(verified, forKey: Self.cachedHasProKey)
}

Pro only goes away when a check finishes and finds no entitlement. A loading state never counts as "no".

August 2026: the sync bug that wasn't CloudKit

After all of those sharing fixes, sync still didn't work for me. Changes on one phone never showed up on the other. CloudKit sync is hard to debug from the outside. The shared database is a black box when it misbehaves, and I can't see what a participant's device sees.

So I did what a lot of developers do at that point. I decided Apple's sync was the problem and that I'd replace it with my own server. I got further down that road than I'd like to admit.

The real cause was much smaller. The build I was testing with wasn't signed. Once I ran a properly signed build, sync worked, and every change showed up on the other device. Nothing in the Core Data stack had to change.

I keep thinking about how close I came to writing a whole backend for a build setting. CloudKit fails quietly, and that makes it very easy to blame the framework. Before you decide CloudKit is broken, check that the build you're running is signed the way a real install would be.

Where it is today

The app is at 2.2.22, and the Monday bot is still bumping it every week. It has 13 event types plus custom ones, three home layouts, widgets, Live Activities, milestones, growth charts, and three languages. It started as a tool for one family, and these days it's mostly for everyone else's.

What the log taught me

  • Pick the boring backend. CloudKit let the app run untouched for 27 months, and it still does the job today.
  • Duplicates are part of the design. Any offline-first sync will create them. Pick a deterministic winner that every device computes the same way, and you never need coordination.
  • Put your own IDs in system objects. Live Activities, shares, and notifications all have their own identifiers. Store yours in them and reconcile on launch.
  • Loading is not "no". Entitlement checks, share discovery, and sync status all have a window where the answer is unknown. Never act on that window as if it were a negative answer.
  • Question the policy before you perfect the code. Two PRs made share revocation correct. One PR removed it, and that was the fix.
  • Check the build before you blame the framework. I almost rewrote the sync layer for a problem that was in how the app was signed.