HomeiOS Developmentios - Fail a construct early if a situation is met (e.g....

ios – Fail a construct early if a situation is met (e.g. secret injection lacking)


Learn how to error out a distribution construct if a secret injection lacking

When secret is not injected correctly, I wish to fail the archive course of (with Swift). It is solely wanted for Distribution builds, as for Debug builds, I wish to construct with out secret injection.

            var apiXSecret: String = Constants.Secrets and techniques.apiXSecret
            #if DISTRIBUTION
            // If secret is not injected, fail the distribution construct
            guard !(apiXSecret.isEmpty) else {
                #error("API X Secret is nil or empty for Distribution")
                return nil
            }
            #endif

The next 2 choices do not find yourself stopping the construct.

  • #error("API Secret is nil or empty") — does not find yourself in construct failure.

  • assert("API Secret is nil or empty") — with assert, detecting this subject can be potential as soon as the check construct is prepared because the app would find yourself crashing for Distribution.

Ideally, I wish to cease the construct course of if the key is not situated throughout compile time.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments