← Back to list

Core Data Diaries #3: I Saved Data… But My UI Still Showed Old Values

This is Part 3 of Core Data Diaries — a series where I break down real Core Data bugs that show up in production

Shashidhar Jagatap · 2026-04-03 08:17 · 41 claps · 2.7 min read paywalled
#ios #ios-app-development #swift #software-development #core-data-swift
Open on Medium ↗
Wiki topics: 📱 · Mobile Development

Core Data Diaries #3: I Saved Data… But My UI Still Showed Old Values

This is Part 3 of Core Data Diaries — a series where I break down real Core Data bugs that show up in production

So far:

Each part helps you:

  • Fix real issues
  • Understand architecture deeply
  • And answer interview questions with confidence

Because:

The bugs you struggle with… are exactly what interviewers ask.

I Saved the Data. Everything Looked Fine.

I saved the data. No errors. Everything looked correct.

But my UI still showed the old value.

That’s when I realized:

Saving data and showing data are two completely different problems.

The Bug That Feels Like a Lie

Here’s what I saw:

  • Data saved successfully ✅
  • No crashes ✅
  • Reopen app → data is there ✅
  • But UI didn’t update ❌

It worked… just not when it mattered.

What I Thought Was Happening

My first thought:

“This must be a SwiftUI refresh issue.”

So I checked:

  • Bindings
  • State updates
  • View refresh logic

Everything looked correct.

What Was Actually Happening

The problem wasn’t UI.

It was this:

My main context didn’t know about background changes

From Part 2, I was doing the right thing:

let context = container.newBackgroundContext()

So now I had:

  • Background context → saving data
  • Main context (viewContext) → driving UI

👉 Two contexts 👉 Two different states

Why UI Shows Old Data

What’s happening:

  • Background context saves
  • Main context doesn’t update
  • UI reads old state

💡 Key Realization

Core Data contexts do NOT automatically sync with each other

This is where things get confusing. Because:

👉 Data is correct 👉 UI is wrong

🥳 The One-Line Fix That Changes Everything

container.viewContext.automaticallyMergesChangesFromParent = true

💥 What This Actually Does

  • Listens for background saves
  • Merges changes into main context
  • Updates UI automatically

Correct Data Flow

🧠 Key Insight (Save This)

Saving data is not enough You must also sync contexts

👉 Save this — you’ll hit this bug again.

The Real Flow (Senior Mental Model)

Now I think like this:

  • User action triggers
  • Background context writes
  • Persistent store updates
  • Main context merges changes
  • UI reflects new data

⚠️ Why This Bug Happens (Common Mistakes)

  • Using background context without merging
  • Assuming save = UI update
  • Not understanding context isolation

🎤 Interview Insight (This Comes Up a Lot)

“Why does UI show stale data even after saving in Core Data?”

✅ Strong Answer

Because Core Data uses multiple contexts that don’t automatically stay in sync. If data is saved in a background context, the main context won’t reflect it unless changes are merged.

Add This (What Makes You Stand Out)

This is not a UI problem — it’s a context synchronization problem.

One-Liner

Core Data consistency is about syncing contexts — not just saving data.

🧠 Final Thought

This is the kind of bug that makes you doubt your entire architecture.

Because:

  • Everything is technically correct
  • But the app still feels broken

If you’ve ever seen:

  • UI not updating
  • Data appearing only after restart
  • “It works… but not instantly”

This is likely why.

Clap • Comment • Save • Share — it helps this reach more developers and support our efforts

Clap • Comment • Save • Share — it helps this reach more developers and support our efforts


메타데이터
post_id
58cd0912d6e8
slug
core-data-diaries-3-58cd0912d6e8
url
https://medium.com/@shashidj206/core-data-diaries-3-58cd0912d6e8
canonical_url
https://medium.com/@shashidj206/core-data-diaries-3-58cd0912d6e8
author_url
https://medium.com/@shashidj206
status
ok
fetched_at
2026-08-02 10:42:44