Development login credentials in Xcode

Danijela Vrzan posted a very cool solution to streamlining entering login credentials in Xcode and the iOS Simulator using breakpoints. I’ll admit that I probably haven’t fully unlocked the full potential of Xcode breakpoints in my development workflow.

If you’re an app developer, no doubt you’ve run into the case where you’re tediously typing in your auth username and passwords every time you rebuild/relaunch the Simulator. It gets old pretty quickly when you’re trying to quickly make updates or fix a bug in your app.

You might consider hard coding some credentials temporarily in your code, but really, you know that’s not what you should be doing, as it clutters up your code and you run the risk of forgetting to remove that code before releasing the app (eep!).

I’ve setup my own solution on how I like to safetly handle this repetitive task in development and avoid needing to type in credentials with the Simulator keyboard.

Development Scheme

For every new project, I setup a dedicated scheme in Xcode for development. The way I set it up is:

  • I like to name this scheme something like Appname (dev) or, if I’m working against a staging environment, I’ll use Appname (staging).
  • In Run > Arguments, add environment variables with keys such as:
    • AUTH_DEFAULT_USERNAME
    • AUTH_DEFAULT_PASSWORD
  • Don’t select Shared so you don’t commit these values into git, especially if these are credentials for a production environment.
  • You could also have multiples of the above variables to quickly switch between different credentials. Xcode lets us choose which ones we want enabled by selecting the checkmark next to each variable.

Pre-filling the Auth Form

import SwiftUI

private var env: [String : String] { ProcessInfo.processInfo.environment }

struct LoginForm: View {
  @State private var username: String = env["AUTH_DEFAULT_USERNAME"] ?? ""
  @State private var password: String = env["AUTH_DEFAULT_PASSWORD"] ?? ""

  // ...
}

Build and Run

Now, with the development scheme you created above enabled, you can run the app and the login form should be pre-filled with the auth credentials in the environment variables.

Voila! No more tedious typing and no credentials stored in code.

As noted previously, you can add multiple credentials into a single scheme, or you could do something like create a new scheme for different environments as well.

Onward

I love seeing tips like the one Danijela has to speed up the develoment workflow. One plus of her method is that it doesn’t require you to make code changes like what we’ve done here. Her method’s certainly made me think more about working with breakpoints in my work.

If we can speed up and optimize the development/test cycle without too much hassle, I consider it a win.

I hope my little tip here can help you out in your own use of Xcode and app development. Let me know if you’ve got more tips like this or if it helped you out.