<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mrugesh Tank</title>
    <description>The latest articles on Forem by Mrugesh Tank (@mrugeshtank).</description>
    <link>https://forem.com/mrugeshtank</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1151116%2F005a0f7b-5f4f-4e36-bcc5-d9b2cdd44688.png</url>
      <title>Forem: Mrugesh Tank</title>
      <link>https://forem.com/mrugeshtank</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mrugeshtank"/>
    <language>en</language>
    <item>
      <title>iOS Privacy Manifest &amp; Required Reasons APIs: A Compliance Checklist</title>
      <dc:creator>Mrugesh Tank</dc:creator>
      <pubDate>Sat, 02 May 2026 04:54:05 +0000</pubDate>
      <link>https://forem.com/mrugeshtank/ios-privacy-manifest-required-reasons-apis-a-compliance-checklist-3o86</link>
      <guid>https://forem.com/mrugeshtank/ios-privacy-manifest-required-reasons-apis-a-compliance-checklist-3o86</guid>
      <description>&lt;p&gt;There's a specific kind of frustration that comes from an App Store rejection you didn't see coming.&lt;/p&gt;

&lt;p&gt;Not a crash. Not a guideline violation. Not a metadata problem. Just a cold rejection email with an error code — ITMS-91053 — and a list of APIs your app called without declaring a reason for calling them.&lt;/p&gt;

&lt;p&gt;APIs you've used for years. APIs that work perfectly. APIs like &lt;code&gt;UserDefaults&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Changed and Why It Matters
&lt;/h2&gt;

&lt;p&gt;Starting May 1, 2024, Apple began enforcing a requirement that had been announced but, frankly, underestimated by a lot of developers: every app must ship with a &lt;code&gt;PrivacyInfo.xcprivacy&lt;/code&gt; privacy manifest file. And if that app — or any SDK it bundles — touches certain system APIs without declaring a reason, the submission is rejected outright.&lt;/p&gt;

&lt;p&gt;No warning. No grace period. Just a rejection and a list of undeclared APIs.&lt;/p&gt;

&lt;p&gt;The requirement exists for a good reason. Third-party SDKs — analytics tools, crash reporters, ad networks — have always had the ability to call sensitive system APIs silently, without any visibility at the app layer. Developers trusted the SDK and moved on. Apple decided that transparency needed to be enforced, not just encouraged.&lt;/p&gt;

&lt;p&gt;That's fair. The implementation, though, catches a lot of developers off guard — because the APIs on the required reasons list aren't obscure. They're everyday tools.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Five APIs That Are Blocking Submissions
&lt;/h2&gt;

&lt;p&gt;Apple currently defines five categories of required reason APIs. If your app uses any of these, you must declare it in your privacy manifest with a specific reason code:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;File Timestamp APIs&lt;/strong&gt; — &lt;code&gt;creationDate&lt;/code&gt;, &lt;code&gt;modificationDate&lt;/code&gt;, &lt;code&gt;getattrlist()&lt;/code&gt;. If you read file metadata anywhere in your app, this applies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;System Boot Time APIs&lt;/strong&gt; — &lt;code&gt;mach_absolute_time()&lt;/code&gt;, &lt;code&gt;systemUptime&lt;/code&gt;. Used for timing events, measuring elapsed time, calculating absolute timestamps. More common than you'd think.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disk Space APIs&lt;/strong&gt; — &lt;code&gt;volumeAvailableCapacityKey&lt;/code&gt;, &lt;code&gt;statfs()&lt;/code&gt;. If your app checks available storage before downloading or writing files, you're calling these.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Active Keyboard APIs&lt;/strong&gt; — &lt;code&gt;activeInputModes&lt;/code&gt;. Narrower use case, but catches keyboard-aware UI work and custom keyboard apps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UserDefaults&lt;/strong&gt; — The entire &lt;code&gt;UserDefaults&lt;/code&gt; class. This is the one that gets almost everyone. Feature flags, user preferences, shared app group settings, SDK internal state — it's all &lt;code&gt;UserDefaults&lt;/code&gt;. If your app runs on iOS, it almost certainly uses this.&lt;/p&gt;

&lt;p&gt;For each category, you don't just declare that you use it — you declare &lt;em&gt;why&lt;/em&gt; you use it, using a specific reason code from Apple's list. &lt;code&gt;CA92.1&lt;/code&gt; means you're reading defaults within your own app. &lt;code&gt;1C8F.1&lt;/code&gt; means you're accessing a shared app group container. The codes are precise, and picking the wrong one is as much of a problem as not declaring at all.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Part That Surprises Developers Most
&lt;/h2&gt;

&lt;p&gt;Your own code is only half the story.&lt;/p&gt;

&lt;p&gt;Every third-party SDK your app bundles is your responsibility. If Firebase, Amplitude, your crash reporter, or any other SDK on Apple's commonly-used list ships without a privacy manifest — or ships with an outdated one — your submission fails. Even if your own &lt;code&gt;PrivacyInfo.xcprivacy&lt;/code&gt; is perfectly complete.&lt;/p&gt;

&lt;p&gt;The safest move before every archive: update all your dependencies to their latest versions, then run &lt;strong&gt;Product → Privacy Report&lt;/strong&gt; in Xcode. This generates a combined PDF of every manifest in your app bundle. Any SDK missing a manifest simply won't appear in the report. That absence is your signal to investigate before submitting — not after.&lt;/p&gt;

&lt;p&gt;I've seen a particular edge case with static CocoaPods where the manifest file exists in the repository but doesn't get correctly bundled by Xcode due to how static library resources are handled. In those cases, the fix is to manually copy the SDK's required API declarations into your own &lt;code&gt;PrivacyInfo.xcprivacy&lt;/code&gt;. Inelegant, but it works.&lt;/p&gt;




&lt;h2&gt;
  
  
  It's A One-Time Investment
&lt;/h2&gt;

&lt;p&gt;Once your manifest is in place and your SDK dependencies are updated, the ongoing maintenance is light. Before each release: check for new API usage you've added, verify any newly integrated SDKs, regenerate the Privacy Report. Five minutes at most.&lt;/p&gt;

&lt;p&gt;The harder part is the first time — understanding which categories apply to your app, reading each reason code carefully to pick the right one, and auditing every SDK in your bundle. That's where most of the time goes.&lt;/p&gt;

&lt;p&gt;Apple has also signalled that this list of required reason APIs can expand in future OS releases. Treating it as a living compliance checklist — rather than a one-time fix — is the right posture.&lt;/p&gt;




&lt;p&gt;I documented the full process: all five API categories, every reason code table, the SDK verification workflow, a 9-point pre-submission checklist, and the common mistakes that cause re-submissions.&lt;/p&gt;

&lt;p&gt;If you're shipping an iOS app and haven't looked at your privacy manifest yet, this is the place to start.&lt;/p&gt;

&lt;p&gt;Read the full article in &lt;a href="https://idiotswithios.com/ios-privacy-manifest-required-reasons-apis-compliance-checklist/" rel="noopener noreferrer"&gt;idiotswithios.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ios</category>
      <category>swift</category>
      <category>mobile</category>
      <category>appstore</category>
    </item>
    <item>
      <title>iOS 26 SDK Migration Guide: What Every App Needs to Update</title>
      <dc:creator>Mrugesh Tank</dc:creator>
      <pubDate>Sat, 25 Apr 2026 12:51:56 +0000</pubDate>
      <link>https://forem.com/mrugeshtank/ios-26-sdk-migration-guide-what-every-app-needs-to-update-45mn</link>
      <guid>https://forem.com/mrugeshtank/ios-26-sdk-migration-guide-what-every-app-needs-to-update-45mn</guid>
      <description>&lt;p&gt;I published a full migration guide on &lt;a href="https://idiotswithios.com" rel="noopener noreferrer"&gt;idiotswithios.com&lt;/a&gt; and wanted to cross-post the key highlights here — because the &lt;strong&gt;April 28 deadline is real&lt;/strong&gt;, and I've already seen teams caught off guard by how much has changed.&lt;/p&gt;

&lt;p&gt;Apple now requires all new App Store submissions and updates to be built with the &lt;strong&gt;iOS 26 SDK&lt;/strong&gt;. Miss the deadline, and your next update gets rejected. Your existing app stays on the store — but you can't push a single update until you're compliant.&lt;/p&gt;

&lt;p&gt;Here's a quick rundown of the 7 steps the full guide covers.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 1 — Update to Xcode 26
&lt;/h2&gt;

&lt;p&gt;Everything starts here. You can't build with the iOS 26 SDK without Xcode 26 or later. Verify your install:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;xcodebuild &lt;span class="nt"&gt;-version&lt;/span&gt;
&lt;span class="c"&gt;# Xcode 26.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you use CI/CD (Xcode Cloud, Bitrise, GitHub Actions) — update your build agents too. A passing local build with a stale CI pipeline will block your App Store submission.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 2 — Fix Deprecated APIs
&lt;/h2&gt;

&lt;p&gt;This is where most of the work is. Open your project in Xcode 26 and build. The warnings are your checklist.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UIKit:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;UIWebView&lt;/code&gt; — fully removed. Won't compile. Migrate to &lt;code&gt;WKWebView&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;UIScreen.main&lt;/code&gt; — deprecated. Use &lt;code&gt;windowScene.screen&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SceneKit&lt;/code&gt; — deprecated. Migrate to &lt;code&gt;RealityKit&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;SwiftUI:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;NavigationView&lt;/code&gt; — deprecated since iOS 16 but still everywhere. Migrate to &lt;code&gt;NavigationStack&lt;/code&gt; or &lt;code&gt;NavigationSplitView&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;actionSheet&lt;/code&gt; — broken in iOS 26. Replace with &lt;code&gt;confirmationDialog&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Quick example — the NavigationView fix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ❌ Before&lt;/span&gt;
&lt;span class="kt"&gt;NavigationView&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;ContentView&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;navigationTitle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Home"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// ✅ After&lt;/span&gt;
&lt;span class="kt"&gt;NavigationStack&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;ContentView&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;navigationTitle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Home"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if you're still on Combine for network calls, now is a good moment to migrate critical paths to &lt;code&gt;async/await&lt;/code&gt;. Also: swap &lt;code&gt;print&lt;/code&gt; for &lt;code&gt;Logger&lt;/code&gt; — it integrates with Instruments and performs better.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 3 — Deployment Target
&lt;/h2&gt;

&lt;p&gt;Building with the iOS 26 SDK does &lt;strong&gt;not&lt;/strong&gt; force you to raise your minimum deployment target. These are two separate settings. That said, this is a natural moment to audit your analytics and drop versions with near-zero user share.&lt;/p&gt;

&lt;p&gt;While you're in there: remove &lt;code&gt;#available&lt;/code&gt; guards for versions you no longer support. Dead guards are noise — and removing them is a clean YAGNI win.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 4 — Privacy Manifest and TLS
&lt;/h2&gt;

&lt;p&gt;Two things to check:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TLS 1.3 is now the default.&lt;/strong&gt; If your app or any SDK you depend on still uses TLS 1.2, those connections will fail silently. Check your dependencies before you archive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Privacy Manifest (&lt;code&gt;PrivacyInfo.xcprivacy&lt;/code&gt;):&lt;/strong&gt; If your app uses &lt;code&gt;UserDefaults&lt;/code&gt;, file timestamps, or disk space — you must declare the approved reason codes. Missing entries fail both Xcode validation and App Store review.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;key&amp;gt;&lt;/span&gt;NSPrivacyAccessedAPICategoryUserDefaults&lt;span class="nt"&gt;&amp;lt;/key&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- reason: CA92.1 --&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;key&amp;gt;&lt;/span&gt;NSPrivacyAccessedAPICategoryFileTimestamp&lt;span class="nt"&gt;&amp;lt;/key&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- reason: C617.1 --&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;key&amp;gt;&lt;/span&gt;NSPrivacyAccessedAPICategoryDiskSpace&lt;span class="nt"&gt;&amp;lt;/key&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- reason: 85F4.1 --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 5 — Handle Liquid Glass
&lt;/h2&gt;

&lt;p&gt;This one is unique to iOS 26. When you rebuild with Xcode 26, standard UIKit and SwiftUI components — nav bars, tab bars, sheets, buttons — &lt;strong&gt;automatically&lt;/strong&gt; adopt the Liquid Glass look. Translucent materials, dynamic blurs, refined controls.&lt;/p&gt;

&lt;p&gt;For apps using standard system UI: this just works.&lt;/p&gt;

&lt;p&gt;For apps with heavy custom UI: navigation bars and sheets behave differently. If you're not ready, Apple gives you a temporary opt-out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Info.plist --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;key&amp;gt;&lt;/span&gt;UIDesignRequiresCompatibility&lt;span class="nt"&gt;&amp;lt;/key&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;true/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This preserves the iOS 18 visual style on iOS 26. Use it as a bridge — Apple will remove this key in a future major release.&lt;/p&gt;

&lt;p&gt;When you're ready to adopt it, SwiftUI makes it easy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kt"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Featured"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;glassEffect&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 6 — Test Before You Archive
&lt;/h2&gt;

&lt;p&gt;Build warnings catch API deprecations. They won't catch:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visual regressions from Liquid Glass&lt;/li&gt;
&lt;li&gt;Layout shifts on navigation and tab bars&lt;/li&gt;
&lt;li&gt;Networking failures from TLS 1.2 → 1.3 changes&lt;/li&gt;
&lt;li&gt;Permission flows on a fresh iOS 26 install&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Test all of these on the iOS 26 simulator before you touch the Archive button.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 7 — Validate and Submit
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Set scheme to &lt;strong&gt;Any iOS Device (arm64)&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Product → Archive&lt;/li&gt;
&lt;li&gt;Organizer → Validate App&lt;/li&gt;
&lt;li&gt;Distribute App → App Store Connect&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Common validation blockers: missing Privacy Manifest entries, lingering Bitcode references (fully removed in Xcode 26), and third-party SDKs that haven't updated yet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Submit at least a week before April 28.&lt;/strong&gt; Review takes 24–48 hours in normal conditions — don't cut it close.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Short Version
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Step&lt;/th&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Update to Xcode 26&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Fix &lt;code&gt;UIWebView&lt;/code&gt;, &lt;code&gt;NavigationView&lt;/code&gt;, &lt;code&gt;actionSheet&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Audit deployment target and &lt;code&gt;#available&lt;/code&gt; guards&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Check Privacy Manifest and TLS 1.2 dependencies&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Decide: adopt Liquid Glass or use the opt-out key&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Test on iOS 26 simulator&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;Validate and submit before April 28&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Most apps will get through this in a few focused days. Legacy UIKit apps with heavy customisation will take longer — especially if third-party dependencies haven't updated. Start now.&lt;/p&gt;




&lt;p&gt;The full guide — with complete code examples, PrivacyInfo.xcprivacy snippets, Liquid Glass UIKit + SwiftUI code, and all Apple documentation references — is on idiotswithios.com.&lt;/p&gt;

&lt;p&gt;→ &lt;strong&gt;&lt;a href="https://idiotswithios.com/ios-26-sdk-migration-guide-what-every-app-needs-to-update/" rel="noopener noreferrer"&gt;iOS 26 SDK Migration Guide: What Every App Needs to Update&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Written by Mrugesh Tank — &lt;a href="https://dev.to/mrugeshtank"&gt;@mrugeshtank on dev.to&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ios</category>
      <category>swift</category>
      <category>swiftui</category>
      <category>mobile</category>
    </item>
    <item>
      <title>SwiftUI Debugging: 6 Techniques Every iOS Dev Should Know</title>
      <dc:creator>Mrugesh Tank</dc:creator>
      <pubDate>Sat, 14 Mar 2026 08:27:03 +0000</pubDate>
      <link>https://forem.com/mrugeshtank/swiftui-debugging-6-techniques-every-ios-dev-should-know-p3h</link>
      <guid>https://forem.com/mrugeshtank/swiftui-debugging-6-techniques-every-ios-dev-should-know-p3h</guid>
      <description>&lt;p&gt;SwiftUI Previews are magical when they work. When they don't, &lt;br&gt;
staring at "Preview crashed" with no clue why is one of the &lt;br&gt;
most frustrating things in iOS development.&lt;/p&gt;

&lt;p&gt;After debugging thousands of preview crashes across multiple &lt;br&gt;
production apps, here are the 6 techniques I reach for every time.&lt;/p&gt;


&lt;h2&gt;
  
  
  Why Do SwiftUI Previews Break?
&lt;/h2&gt;

&lt;p&gt;Previews run in a &lt;strong&gt;sandboxed environment&lt;/strong&gt; separate from your app. &lt;br&gt;
They have stricter resource limits, no access to your app's &lt;br&gt;
environment by default, and their own compiler pipeline. &lt;br&gt;
Once you internalize this, most failures become predictable.&lt;/p&gt;

&lt;p&gt;Four root causes cover 90% of cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compile-time errors (one broken file cascades across the project)&lt;/li&gt;
&lt;li&gt;Runtime errors (force unwraps, nil crashes)&lt;/li&gt;
&lt;li&gt;Missing environment dependencies (environmentObject not injected)&lt;/li&gt;
&lt;li&gt;Complexity/timeout (view does too much, exceeds preview's time limit)&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Technique 1 — Build explicitly first
&lt;/h2&gt;

&lt;p&gt;Hit &lt;code&gt;Cmd+B&lt;/code&gt; before anything else. The preview compiler sometimes &lt;br&gt;
fails silently while your main target builds fine. Check the build &lt;br&gt;
output for errors in files you weren't even editing.&lt;/p&gt;


&lt;h2&gt;
  
  
  Technique 2 — &lt;code&gt;Self._printChanges()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This underused API tells you &lt;strong&gt;exactly&lt;/strong&gt; why SwiftUI re-evaluated &lt;br&gt;
your view's body:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;some&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;Self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;_printChanges&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="c1"&gt;// your view...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The console will log which &lt;code&gt;@State&lt;/code&gt; or &lt;code&gt;@ObservedObject&lt;/code&gt; property &lt;br&gt;
changed and triggered the re-render. Invaluable for infinite &lt;br&gt;
re-render loops.&lt;/p&gt;


&lt;h2&gt;
  
  
  Technique 3 — Use &lt;code&gt;Logger&lt;/code&gt;, not &lt;code&gt;print()&lt;/code&gt;
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;OSLog&lt;/span&gt;

&lt;span class="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;ProfileView&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Logger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nv"&gt;subsystem&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"com.yourapp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
        &lt;span class="nv"&gt;category&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"ProfileView"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;some&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;debug&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"body evaluated"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;// your view...&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Logger is type-safe, shows up in Console.app with filtering, &lt;br&gt;
and gets stripped from release builds automatically.&lt;/p&gt;


&lt;h2&gt;
  
  
  Technique 4 — Isolate by binary search
&lt;/h2&gt;

&lt;p&gt;Comment out &lt;strong&gt;half&lt;/strong&gt; your view body. If preview works → problem is &lt;br&gt;
in the commented half. Still crashes → problem is in the remaining &lt;br&gt;
half. Keep halving until you find the exact line.&lt;/p&gt;

&lt;p&gt;If you can't isolate a view without breaking everything, &lt;br&gt;
your components are too tightly coupled. That's the real bug.&lt;/p&gt;


&lt;h2&gt;
  
  
  Technique 5 — Inject mock dependencies
&lt;/h2&gt;

&lt;p&gt;Never make real network calls from previews. Use protocol-based &lt;br&gt;
injection so you can swap in a mock:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;protocol&lt;/span&gt; &lt;span class="kt"&gt;DataFetching&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;fetchUsers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;MockDataFetcher&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;DataFetching&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;fetchUsers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Mrugesh Tank"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"m@test.com"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cp"&gt;#Preview {&lt;/span&gt;
    &lt;span class="kt"&gt;UserListView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;dataFetcher&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;MockDataFetcher&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Technique 6 — Centralize preview mock data
&lt;/h2&gt;

&lt;p&gt;Instead of scattering mock objects across every preview block, &lt;br&gt;
create a single &lt;code&gt;PreviewHelpers.swift&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="cp"&gt;#if DEBUG&lt;/span&gt;
&lt;span class="kd"&gt;enum&lt;/span&gt; &lt;span class="kt"&gt;PreviewData&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Test User"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;admin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Jane"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;member&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="cp"&gt;#endif&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your previews become clean and consistent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="cp"&gt;#Preview { ProfileView(user: PreviewData.user) }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  The Bigger Lesson
&lt;/h2&gt;

&lt;p&gt;Views that preview reliably are almost always well-architected views. &lt;br&gt;
Preview instability is usually a symptom of tight coupling, &lt;br&gt;
missing dependency injection, or views doing too much.&lt;/p&gt;

&lt;p&gt;The path to stable previews is the same as the path to &lt;br&gt;
maintainable, testable SwiftUI code.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;I wrote a more detailed version of this with additional &lt;br&gt;
patterns on my blog:&lt;/em&gt;&lt;br&gt;
👉 &lt;a href="https://idiotswithios.com/swiftui-debugging-powerful-mind-blowing-ways/" rel="noopener noreferrer"&gt;Full article on idiots With iOS&lt;/a&gt;&lt;/p&gt;

</description>
      <category>swiftui</category>
      <category>ios</category>
      <category>swift</category>
      <category>debugging</category>
    </item>
  </channel>
</rss>
