Feature: Remove package for production version
Hi, Thanks for your great work on DebugSwift! The package is really helpful during development, but in many cases, we want to completely remove it from production builds — similar to how other debug tools like FLEX allow full exclusion.
Currently, when using DebugSwift via Swift Package Manager, the package (and all its files) are always compiled and linked, even if we disable it at runtime (e.g., using DebugSwift.disable() in release builds). This causes:
- Unwanted binary bloat
- Security/code audit concerns
- Longer compile times
Suggested Solution:
You can simply add a unique prefix like DebugSwift.<rest of name> to all your file names, which makes it easy to exclude them from production builds using the EXCLUDED_SOURCE_FILE_NAMES setting in the build settings.
Thanks again for your work on this! We'd love to see support for this feature to make DebugSwift even more flexible and production-safe.
Hey @Ali72, thanks so much for you amazing comment! Can you try this approach first?
🛠️ Step-by-Step: Isolating DebugSwift via a Target-Based Dependency
🧱 Step 1: Create a New “DebugSupport” Target
This new target will contain all debug-only dependencies and logic.
In Xcode:
- Go to File > New > Target…
- Select Framework > Swift Framework
- Name it
DebugSupport - Make sure it’s added to the Debug build configuration only (more on that in Step 5)
🔗 Step 2: Add DebugSwift to DebugSupport Only
If using Swift Package Manager:
-
Open Project Settings > Package Dependencies
-
Add
DebugSwiftif you haven’t already -
In the Framework & Library section of the
DebugSupporttarget:- Add
DebugSwift.framework(under "Link Binary with Libraries")
- Add
🧠 You're now isolating the debug dependency to a separate module.
📦 Step 3: Re-export DebugSwift from DebugSupport (Optional)
In DebugSupport.swift inside the new target:
@_exported import DebugSwift
✅ This makes
DebugSwiftAPIs directly accessible to other modules that importDebugSupport.
🧪 Step 4: Use DebugSupport in Your App Target (Debug Only)
In your main app target, conditionally import and use:
#if DEBUG
import DebugSupport
func setupDebugTools() {
DebugSwift.enable()
}
#endif
This ensures all usage is scoped to debug builds only.
⚙️ Step 5: Limit DebugSupport to Debug Builds Only
In Build Settings for your app target:
-
Go to Build Phases > Link Binary With Libraries
-
Add
DebugSupport.frameworkonly for theDebugconfiguration:- Click the
+icon and addDebugSupport.framework - Then click the dropdown > Do Not Embed / Debug only
- Click the
Optional:
-
You can also use Xcode Schemes:
- Duplicate your main scheme as “Release”
- In Edit Scheme > Build > Targets, uncheck
DebugSupportfrom the “Release” scheme
🧹 Step 6: Clean Up Imports in Your App
You should now:
-
Remove direct imports of
DebugSwiftfrom your app code - Only import
DebugSupport(guarded by#if DEBUG) - This will fully isolate the debug tooling to debug builds and prevent any runtime references from leaking into release builds
✅ Benefits of This Approach
- 💡 Keeps production binary lean (no dead code, no linked debug tools)
- 🔒 Reduces risk of exposing debug APIs in production
- 🔁 Reusable pattern for other debug tools like FLEX, Reveal, etc.
If works, can you open a PR adding a md in a folder docs and add the ref in the readme? how use only in debug 😅