CargoBayStatusCode typedef Question
wtholliday opened this issue · 9 comments
I get link errors otherwise.
Really? It's just a regular enum
(NS_ENUM
). I don't think this is the problem.
Can you elaborate? Copy paste the aforementioned link errors?
Notice the difference in the declaration between CargoBayStatusCode and CargoBayErrorCode. The latter is a typedef.
Link errors are:
duplicate symbol _CargoBayStatusCode in...
Adding the typedef keyword fixed it. The compiler is generating an actual variable, hence the link error.
Here's the preprocessed source:
NSInteger CargoBayStatusCode; enum {
CargoBayStatusOK = 0,
CargoBayStatusCannotParseJSON = 21000,
CargoBayStatusMalformedReceiptData = 21002,
CargoBayStatusCannotAuthenticateReceiptData = 21003,
CargoBayStatusSharedSecretDoesNotMatch = 21004,
CargoBayStatusReceiptServerUnavailable = 21005,
CargoBayStatusReceiptValidButSubscriptionExpired = 21006,
CargoBayStatusSandboxReceiptSentToProduction = 21007,
CargoBayStatusProductionReceiptSentToSandbox = 21008
};
This results in an NSInteger global being declared in each file I include CargoBay.
If a static
declaration also fixes your issue, that would be the desired change.
Then why is CargoBayErrorCode declared as a typedef?
Everywhere I see online, including your own article, NS_ENUM is preceded by the typedef keyword.
Then why is CargoBayErrorCode declared as a typedef?
Because it's actually used as a type. CargoBayStatusCode
is just an enum
used to define constants. It could just as well be enum
instead of NS_ENUM
.
Does it preprocess to something different on your end? The above preprocessed source would cause a declaration of CargoBayStatusCode in each file where CargoBay.h is included, which unless I'm going crazy, causes link errors.
Ok, when I make a new project, it does preprocess to something else:
enum CargoBayStatusCode : NSInteger CargoBayStatusCode; enum CargoBayStatusCode : NSInteger {
CargoBayStatusOK = 0,
CargoBayStatusCannotParseJSON = 21000,
CargoBayStatusMalformedReceiptData = 21002,
CargoBayStatusCannotAuthenticateReceiptData = 21003,
CargoBayStatusSharedSecretDoesNotMatch = 21004,
CargoBayStatusReceiptServerUnavailable = 21005,
CargoBayStatusReceiptValidButSubscriptionExpired = 21006,
CargoBayStatusSandboxReceiptSentToProduction = 21007,
CargoBayStatusProductionReceiptSentToSandbox = 21008
};
Sigh.
Oh, ok I see why. You can't import CargoBay.h in an Objective-C++ (.mm) file.
Here's a simple project which demonstrates the link errors:
https://dl.dropboxusercontent.com/u/45540223/CargoBayTest.zip