QuickTip Series #1

iOS Environnement based pods

Hello there,
I’m so excited to start this Quicktip series today. The goal of this serie of articles is to give you some tips in a short, precise and consise way. So enough talk and let’s get started.

Goal

The idea is to be able to have different podfile configurations based on the current environnement.

Tip

Simply check environnement variables in your podfile.
You can access and environnement variable this way : ENV['USER']

Example

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'
use_frameworks!
inhibit_all_warnings!

target 'TargetName' do

    if ['anas'].include?(ENV['USER']) #1
    	# IF CURRENT USER IS ME, I use the local path
    	pod 'AABlurAlertController', :path => "#{ENV['POD_LOCAL_HOME']}/AABlurAlertController"
    	
       else
       # ELSE (CI for example) I use the github repository
       pod 'AABlurAlertController', :git => 'git@github.com:anas10/AABlurAlertController.git', :branch => 'master'
       
    end

    pod 'AASquaresLoading'
	[...]
	
    target 'TargetNameTests' do
        inherit! :search_paths
        
		 [...]
    end
end

The important part is #1 where we check the environement user and then act accordingly.

Here we go with our first quick tip.
Let me know what you think and see you soon.

UPDATE : 04/04/17

I did something else recently that makes more sense in many cases.
Instead of looking for the user via an environment variable, I just look for a specific environnement variable such as LOCALPODS

if ENV['LOCALPODS']
	pod 'AABlurAlertController', :path => "#{ENV['POD_LOCAL_HOME']}/AABlurAlertController"    
else
	pod 'AABlurAlertController', :git => 'git@github.com:anas10/AABlurAlertController.git', :branch => 'master'
end

Ans I set this variable only when needed before a pod install like this : LOCALPODS=true pod install