Stripe-ios: use of "@import" break projects using Objective-C++

Created on 30 Aug 2015  Â·  5Comments  Â·  Source: stripe/stripe-ios

It looks like the @import directives in version 5.x.x break the Xcode compile whenever a .mm file tries to import a Stripe header (in my case, it's STPToken.h).

Is there any plan to make this version Objective-C++ compatible? Otherwise we're stuck with version 3.1.0.

Most helpful comment

For the time being, I'm manually amending the Stripe SDK header files, wrapping lines such as:

@import Foundation;

in proper compile-time checks for the Clang modules feature:

#if __has_feature(modules)
    @import Foundation;
#else
    #import <Foundation/Foundation.h>
#endif

All 5 comments

Hey there,
Can you provide a bit more context here? Specifically, what errors are you seeing? Also, how are you integrating our SDK? Are you building the source alongside your own project, or integrating it via a build tool such as CocoaPods or Carthage? I admittedly haven't written much Objective-C++, so any context you can provide is helpful. If you have the time to put together a small sample app that reproduces your issue, that'd be wonderful. Generally speaking though using @import directives is helpful for a lot of reasons so I'd prefer to just find a way to make things work for you with what we have now.

I would also like to update from version 4.0.x to 5.1, but the use of the @import directive is a showstopper! Our Stripe-enabled iOS project uses Objective-C++ all over the place, and as of Xcode 6.4, modules are force-disabled when compiling .mm files (_even_ if you have "Enable Modules" switched on in your target settings [CLANG_ENABLE_MODULES, -fmodules]).

You can see this for yourself if you change the extension of one of your source files from .m to .mm -- you'll start seeing errors like this:

In file included from /Users/marco/Ovolab/RoseAndMary/Customer/iOS/Classes/AppDelegate/AppDelegate.mm:12:
In file included from ../../Common/Frameworks/Stripe.framework/Headers/Stripe.h:9:
../../Common/Frameworks/Stripe.framework/Headers/STPAPIClient.h:9:1: error: use of '@import' when modules are disabled
@import Foundation;
^

For the time being, I'm manually amending the Stripe SDK header files, wrapping lines such as:

@import Foundation;

in proper compile-time checks for the Clang modules feature:

#if __has_feature(modules)
    @import Foundation;
#else
    #import <Foundation/Foundation.h>
#endif

@ortekka that seems like the right thing to do – mind making a PR?

This is now fixed on master and the just-relesaed version 5.1.3.

Was this page helpful?
0 / 5 - 0 ratings