Skip to content

Commit aff54c0

Browse files
dadachiclaude
andcommitted
Read API endpoint from env vars in Debug builds
Debug builds now read NATEMPLATE_API_SCHEME/DOMAIN/PORT from the scheme's environment variables, falling back to production defaults when unset. README documents the local-API workflow and keeping the scheme in xcuserdata (per-developer, gitignored) instead of xcshareddata. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 633f411 commit aff54c0

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

NativeAppTemplate/Constants.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,9 @@ enum NativeAppTemplateConstants {
9494

9595
extension String {
9696
#if DEBUG
97-
// static let scheme: String = "http"
98-
// static let domain: String = "192.168.1.21"
99-
// static let port: String = "3000"
100-
static let scheme: String = "https"
101-
static let domain: String = "api.nativeapptemplate.com"
102-
static let port: String = ""
97+
static let scheme: String = ProcessInfo.processInfo.environment["NATEMPLATE_API_SCHEME"] ?? "https"
98+
static let domain: String = ProcessInfo.processInfo.environment["NATEMPLATE_API_DOMAIN"] ?? "api.nativeapptemplate.com"
99+
static let port: String = ProcessInfo.processInfo.environment["NATEMPLATE_API_PORT"] ?? ""
103100
#else
104101
static let scheme: String = "https"
105102
static let domain: String = "api.nativeapptemplate.com"

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,21 @@ To run this app successfully, ensure you have:
141141

142142
## Running with the NativeAppTemplate-API on localhost
143143

144-
To connect to a local API server, update the following configuration in in Constants.swift:
144+
To connect to a local API server, set these env vars on the Xcode scheme (Edit Scheme → Run → Arguments → Environment Variables):
145145

146-
```swift
147-
static let scheme: String = "http"
148-
static let domain: String = "192.168.1.21"
149-
static let port: String = "3000"
150146
```
147+
NATEMPLATE_API_SCHEME = http
148+
NATEMPLATE_API_DOMAIN = <your-lan-ip>
149+
NATEMPLATE_API_PORT = 3000
150+
```
151+
152+
Keep the scheme in `xcuserdata` (per-developer, gitignored), not `xcshareddata`. In Xcode, open **Product → Scheme → Manage Schemes…**, find `NativeAppTemplate`, and **uncheck "Shared"**. This moves the scheme (with your local env vars) to `xcuserdata/<user>.xcuserdatad/xcschemes/` so your API settings are not committed. If Xcode staged a deletion of the previously shared scheme, restore it with:
153+
154+
```bash
155+
git restore --source=HEAD --staged --worktree NativeAppTemplate.xcodeproj/xcshareddata/xcschemes/NativeAppTemplate.xcscheme
156+
```
157+
158+
Debug builds read these at launch via `ProcessInfo.processInfo.environment` in `Constants.swift`; when unset, they fall back to the production defaults (`https://api.nativeapptemplate.com`). Release builds always use the production defaults.
151159

152160
## SwiftLint
153161

0 commit comments

Comments
 (0)