Latest 0.1.8
Homepage https://github.com/gametimesf/GAMConstants
License MIT
Platforms ios 9.0, requires ARC
Authors

A Constant and Localizable strings manager that allow for easy production & beta developemnt with the additional capability of overriding values from your server

Installation

Version
Platform
Carthage compatible

Cocoapods

GAMConstants is available through CocoaPods, to install
it simply add the following line to your Podfile:

pod "GAMConstants"

Carthage

github "gametimesf/GAMConstants" == 0.1.8

Building

GAMConstants 0.1.8 requires Swift 2.2

Usage

In Your AppDelegate.swift configure the constants manager with a production plist and staging plist. Based on your current environment pass an override config or not.

We use the overrideConfigFile in our local development environments to
allow easily customization of your production constants. For things like
Braintree, hitting a development server, or using a custom Mixpanel
account is all done through redefining the constant in the
overrideConfigFile

See the following example below for how we override our production
values based on the DEBUG flag Xcode gives you

Set up

class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    #if DEBUG
        GAMConstantsManager.sharedInstance.config = alphaConfig()
    #else
        GAMConstantsManager.sharedInstance.config = prodConfig()
    #endif

        return true
    }

    // Where Constants is a .plist file in your /Resources directory
    private class func prodConfig() -> GAMConstantsManagerConfig {
        return GAMConstantsManagerConfig(defaultConfigFile: "Constants",
                                        overrideConfigFile: nil
        )
    }

    // Where Constants_testing is a .plist file in your /Resources directory
    private class func alphaConfig() -> GAMConstantsManagerConfig {
        return GAMConstantsManagerConfig(defaultConfigFile: "Constants",
                                        overrideConfigFile: "Constants_testing"
        )
    }
}

In Use

Constants

import GAMConstants
class MyTableViewController : UITableViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        GMSServices.provideAPIKey(GAMConstantsManager.sharedInstance.stringForID("google_maps_api_key))
    }
}

Strings

Add a file titled: Resources/Localizable.strings file inside of /Resources where you might have the following keys

"MyTableViewController.TITLE" = "My first Table View Controller";
"MyTableViewController.WelcomeBack.User" = "Welcome back, %@";

And then you can simply call:

import GAMConstants
class MyTableViewController : UITableViewController {
    @IBOutlet private weak var userWelcomeBackLabel: UILabel?

    override func viewDidLoad() {
        super.viewDidLoad()

        title = "MyTableViewController.TITLE".localized()
        userWelcomeBackLabel?.text = "MyTableViewController.TITLE".localizedWithArgs("Mike")
    }
}

Interceptions

Now the real power of GAMConstants comes into play. The ability to on the fly override constants and strings. Simply add an interceptions_url string value pointing to your server in your Constants.plist file returning the following structure:

"hotfixes": {
    "google_maps_api_key": "abc123",
    "MyTableViewController.WelcomeBack.User": "Hi, %@",
}

Now with this on applaunch, the constants manager will automatically make an api call to the interceptions_url you configured above and allow easy override of values you have configured in either your Resources/Localizable.strings file and Resources/Constants.plist file

So now if we take the above example:

import GAMConstants
class MyTableViewController : UITableViewController {
    @IBOutlet private weak var userWelcomeBackLabel: UILabel?

    override func viewDidLoad() {
        super.viewDidLoad()

        title = "MyTableViewController.TITLE".localized()
        userWelcomeBackLabel?.text = "MyTableViewController.TITLE".localizedWithArgs("Mike")
    }
}

The userWelcomeBacklabel will now output => Hi, Mike instead of the Welcome back, Mike as defined in our Localization file.

Usage inside of Storyboards

Here at Gametime we love Storyboards and xibs. And with the advent of @IBInspectable it is now easier then ever to localize UILabels, UIButtons, UIBarButtonItems, and UIViewController titles. If you installed the framework with Cocoapods your work here is done. Simply open any Storyboard file and click on a UILabel and you will now see the new fields rendered automatically. If You used Carthage you will need to copy and paste extension-GAMConstantsInspectable into your repo due to the framework not living inside your application

Updates

  • 0.1.18: Initial release for use with both Carthage and Cocoapods

Requirements

  • Xcode 7
  • iOS 9

Authors

License

GAMConstants is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "GAMConstants",
    "version": "0.1.8",
    "summary": "Easy to use framework for managing Constants and String localization all while being changeable from your server.",
    "description": "Easy to use framework for managing Constants and String localization all while being changeable from your server. Simply configure your server with an interceptions file and all constants will be changed",
    "homepage": "https://github.com/gametimesf/GAMConstants",
    "license": "MIT",
    "authors": {
        "Mike Silvis": "[email protected]"
    },
    "source_files": "Source/*.swift",
    "exclude_files": "Classes/Exclude",
    "ios": {
        "frameworks": [
            "Foundation",
            "UIKit"
        ]
    },
    "platforms": {
        "ios": "9.0"
    },
    "requires_arc": true,
    "source": {
        "git": "https://github.com/gametimesf/GAMConstants.git",
        "tag": "0.1.8"
    }
}

Pin It on Pinterest

Share This