Both the AuthNet and PayPal mobile payment libraries have the ENV_LIVE enumerator defined. This reults in Xcode errors like:
Redefinition of enumerator 'ENV_LIVE' ...
In cases like this where one cannot afford to simply change the source code of dependent frameworks, what are some workarounds available in objective-c syntax or xcode configuration?
INITIALLY:
#import "PayPal.h"
#import "AuthNet.h"
...
// AuthNet
[AuthNet authNetWithEnvironment:ENV_TEST];
// PayPal
if (STATUS_COMPLETED_SUCCESS == [PayPal initializationStatus]) {
[PayPal initializeWithAppID:@"APP-XXX" forEnvironment:ENV_SANDBOX];
}
UPDATE (here’s what I ended up using as a workaround based on the correct answer):
#import "PayPal.h"
@class AuthNet;
#import "AuthNetWorkaround.h"
...
[AuthNet authNetWithEnvironment:AUTHNET_ENV_TEST];
extern const int AUTHNET_ENV_LIVE;
extern const int AUTHNET_ENV_TEST;
@interface AuthNetWorkaround : NSObject
@end
#import "AuthNetWorkaround.h"
#import "AuthNet.h"
@implementation AuthNetWorkaround
const int AUTHNET_ENV_LIVE = ENV_LIVE;
const int AUTHNET_ENV_TEST = ENV_TEST;
@end
This happens because both inclusions happen in the same compilation unit. You can work around this problem by moving the inclusion of one of the enums into a separate compilation unit, at a cost of making the values of that enumerator non-compile-time constants (in fact, they become global variables).
In pp_workaround.h:
In pp_workaround.m:
Now you can include
"pp_workaround.h"instead of"PayPal.h", and usePAYPAL_ENV_LIVEinstead ofENV_LIVE. Not everything will work the same, but the compile-time error should be gone.EDIT If your code lets you import the conflicting headers only in your .m file, you can fix the problem (rather than working around it) by wrapping the connection code in an additional abstraction layer of your own, like this:
In the paypal_init.h:
In the paypal_init.m:
in the authnet_init.h:
in the authnet_init.m:
In your main file: