Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning - "treating #import as an import of module 'Foundation'" #10

Closed
mathaeus opened this issue Jan 3, 2022 · 7 comments
Closed

Comments

@mathaeus
Copy link

mathaeus commented Jan 3, 2022

Hi, we are seeing lots of warnings of

treating #import as an import of module 'Foundation'"

Please see below.

SDK integrated via SPM
Appboy_iOS_SDK: https://github.com/braze-inc/braze-ios-sdk @ 4.4.1

 ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/Appboy.h:11:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:44]: ▸ #import <Foundation/Foundation.h>
[14:49:44]: ▸ ^
[14:49:44]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/Appboy.h:12:1: treating #import as an import of module 'UIKit' [-Wauto-import]
[14:49:44]: ▸ #import <UIKit/UIKit.h>
[14:49:44]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/Appboy.h:13:1: treating #import as an import of module 'UserNotifications' [-Wauto-import]
[14:49:45]: ▸ #import <UserNotifications/UserNotifications.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKUser.h:5:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:45]: ▸ #import <Foundation/Foundation.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKFacebookUser.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:45]: ▸ #import <Foundation/Foundation.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKTwitterUser.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:45]: ▸ #import <Foundation/Foundation.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKAttributionData.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:45]: ▸ #import <Foundation/Foundation.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKCard.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:45]: ▸ #import <Foundation/Foundation.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKFeedController.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:45]: ▸ #import <Foundation/Foundation.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKContentCard.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:45]: ▸ #import <Foundation/Foundation.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKSdkAuthenticationError.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:45]: ▸ #import <Foundation/Foundation.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKSdkAuthenticationDelegate.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:45]: ▸ #import <Foundation/Foundation.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessage.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:45]: ▸ #import <Foundation/Foundation.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessage.h:2:1: treating #import as an import of module 'UIKit' [-Wauto-import]
[14:49:45]: ▸ #import <UIKit/UIKit.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessage.h:61:67: implicit conversion increases floating-point precision: 'float' to 'CGFloat' (aka 'double') [-Wdouble-promotion]
[14:49:45]: ▸ static CGFloat const RedValueOfDefaultIconColorAndButtonBgColor = 0.0f;
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessage.h:62:76: implicit conversion increases floating-point precision: 'float' to 'CGFloat' (aka 'double') [-Wdouble-promotion]
[14:49:45]: ▸ static CGFloat const GreenValueOfDefaultIconColorAndButtonBgColor = 115.0f / 255.0f;
[14:49:45]: ▸                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   ^~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessage.h:63:75: implicit conversion increases floating-point precision: 'float' to 'CGFloat' (aka 'double') [-Wdouble-promotion]
[14:49:45]: ▸ static CGFloat const BlueValueOfDefaultIconColorAndButtonBgColor = 213.0f / 255.0f;
[14:49:45]: ▸                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   ~~~~~~~^~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessage.h:64:69: implicit conversion increases floating-point precision: 'float' to 'CGFloat' (aka 'double') [-Wdouble-promotion]
[14:49:45]: ▸ static CGFloat const AlphaValueOfDefaultIconColorAndButtonBgColor = 1.0f;
[14:49:45]: ▸                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   ~~~~~~~^~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessageHTML.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:45]: ▸ #import <Foundation/Foundation.h>
[14:49:45]: ▸                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   ^~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessageHTMLBase.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:45]: ▸ #import <Foundation/Foundation.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessageHTMLFull.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:45]: ▸ #import <Foundation/Foundation.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessageControllerDelegate.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:45]: ▸ #import <Foundation/Foundation.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessageController.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:45]: ▸ #import <Foundation/Foundation.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessageUIControlling.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:45]: ▸ #import <Foundation/Foundation.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:45]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessageWebViewBridge.h:1:1: treating #import as an import of module 'WebKit' [-Wauto-import]
[14:49:45]: ▸ #imp
ort <WebKit/WebKit.h>
[14:49:45]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessageDarkTheme.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:46]: ▸ #import <Foundation/Foundation.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessageDarkTheme.h:2:1: treating #import as an import of module 'UIKit' [-Wauto-import]
[14:49:46]: ▸ #import <UIKit/UIKit.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessageDarkButtonTheme.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:46]: ▸ #import <Foundation/Foundation.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKInAppMessageDarkButtonTheme.h:2:1: treating #import as an import of module 'UIKit' [-Wauto-import]
[14:49:46]: ▸ #import <UIKit/UIKit.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKContentCardsController.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:46]: ▸ #import <Foundation/Foundation.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKIDFADelegate.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:46]: ▸ #import <Foundation/Foundation.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKSDWebImageProxy.h:1:1: treating #import as an import of module 'UIKit' [-Wauto-import]
[14:49:46]: ▸ #import <UIKit/UIKit.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKImageDelegate.h:1:1: treating #import as an import of module 'UIKit' [-Wauto-import]
[14:49:46]: ▸ #import <UIKit/UIKit.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKLocationManager.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:46]: ▸ #import <Foundation/Foundation.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKLocationManager.h:2:1: treating #import as an import of module 'CoreLocation' [-Wauto-import]
[14:49:46]: ▸ #import <CoreLocation/CoreLocation.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKLocationManagerProvider.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:46]: ▸ #import <Foundation/Foundation.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKURLDelegate.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:46]: ▸ #import <Foundation/Foundation.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKPushUtils.h:2:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:46]: ▸ #import <Foundation/Foundation.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKPushUtils.h:3:1: treating #import as an import of module 'UserNotifications' [-Wauto-import]
[14:49:46]: ▸ #import <UserNotifications/UserNotifications.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKPushUtils.h:4:1: treating #import as an import of module 'UIKit' [-Wauto-import]
[14:49:46]: ▸ #import <UIKit/UIKit.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKModalWebViewController.h:1:1: treating #import as an import of module 'UIKit' [-Wauto-import]
[14:49:46]: ▸ #import <UIKit/UIKit.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKModalWebViewController.h:2:1: treating #import as an import of module 'WebKit' [-Wauto-import]
[14:49:46]: ▸ #import <WebKit/WebKit.h>
[14:49:46]: ▸ ^~~~~~~~~~~~~~~~~~~~~~~
[14:49:46]: ▸ ⚠️  **************************/checkouts/braze-ios-sdk/AppboyKit/include/ABKNoConnectionLocalization.h:1:1: treating #import as an import of module 'Foundation' [-Wauto-import]
[14:49:46]: ▸ #import <Foundation/Foundation.h>
@lowip
Copy link
Collaborator

lowip commented Jan 18, 2022

Hi @mathaeus,

Thanks for reporting this issue. Unfortunately we are unable to reproduce it (Xcode 13.2), could you provide more information about your setup (e.g. Xcode version, SwiftUI, etc.)?

@mathaeus
Copy link
Author

mathaeus commented Jan 18, 2022

It's not a very special setup, but it is a mixed Objc/Swift code base and from what I can see somehow the bridging headers are involved.

braze_warning

But anyway, the fix should be simple.
Instead of

#import <Foundation/Foundation.h>

use

@import Foundation;

That's the more performant option anyway.


EDIT: For the sake of completeness: I'm on Xcode 13.2.1, Braze SDK 4.4.1

@lowip
Copy link
Collaborator

lowip commented Jan 19, 2022

Hey @mathaeus,

Thanks for these details. By default, Xcode should not generate this warning unless the compiler option -Wauto-import flag is set (usually in the OTHER_CFLAGS build setting). What is strange to me is that this flag should not influence the compilation of AppboyKit/AppboyUI when integrated via SPM.

I was able to trigger a similar warning by setting the build setting OTHER_CFLAGS=-Wauto-import and importing an AppboyUI class directly in an ObjC file (either .h or .m) but not when importing it in a bridging header.

Possible solutions:

  1. Remove imports of Appboy related classes in your bridging header
    • When integrating with SPM, you can directly import either AppboyKit or AppboyUI in swift source files (e.g. import AppboyUI)
  2. Remove the -Wauto-import compiler flag if possible

If none of the above works for you, could you send us the output of the terminal command xcodebuild -showBuildSettings -scheme <MY_APP_SCHEME> (please run this command where your .xcodeproj / .xcworkspace resides) at [email protected] and making sure to reference this Github issue.

Best.

@mathaeus
Copy link
Author

Hi @lowip, thanks for looking into it.

but not when importing it in a bridging header.

From my screenshot above one can see that it seems to be the "generated swift bridge", so not the bridging header for importing Objc code into Swift. Sorry if my wording was confusing.

That having said, we don't import any AppboyXXX in Objc and therefore also don't import any such classes in our bridging header from Objc -> Swift, hence suggested solution 1 can't be applied.


About 2) removing the compiler flag. I think it's common to have this compiler flag turned on, so turning it off doesn't sound like a long-term solution to me :)


Have you considered replacing the imports as I suggested?

@lowip
Copy link
Collaborator

lowip commented Jan 20, 2022

Hi @mathaeus,

From my screenshot above one can see that it seems to be the "generated swift bridge", so not the bridging header for importing Objc code into Swift. Sorry if my wording was confusing.

No worries, I couldn't find any reference online to a Generated-Swift-Bridge.h file so I assumed this was an app bridging header instead of an SPM-generated bridge.

Have you considered replacing the imports as I suggested?

I agree with you that in today's world, the @import ObjC syntax makes more sense. On our side, adopting this syntax properly would be a non-negligible task as this means updating not only our codebase, but all of our sample apps and related documentation.

With the upcoming release of our Swift SDK which will replace our ObjC SDK, this work would also quickly become obsolete.

I think it's common to have this compiler flag turned on, so turning it off doesn't sound like a long-term solution to me :)

I am curious about the reasoning with enabling this warning flag in your project. Auto-imports have been first mentioned in clang 3.3 release notes (2013) as a future direction. I haven't found much more about that feature online (e.g. SO search) and this flag is also not part of the usual umbrella warning flags -Wall, -Wextra and -pedantic. Apart from forcing the @import syntax for code-style reasons, I can't see any advantage in enabling this flag in an ObjC context but I might be missing something.

@mathaeus
Copy link
Author

Hi @lowip , thanks for the follow up.

Glad to hear that you're working on a Swift SDK 👍.
Okay agreed, then it doesn't make sense to fix this now from your side, no worries :)

About the flag, I think most projects I worked on had this flag turned on. I'm also no expert about this, but auto-imports in general are a nice thing, because it makes it obsolete to link the system frameworks explicitly.

That having said, we can live with the warning for now. I'm therefore also closing this issue. Thanks again for your input!

@lowip
Copy link
Collaborator

lowip commented Jan 20, 2022

Thanks for understanding our situation :).

I think you can safely remove that flag as the W in -Wauto-import stands for enabling warnings for a specific feature. That flag explicitly warns you when an auto-import occurs. It does not turn on auto imports as this is a feature enabled by default in Xcode.

As a reference, -Wall means enables all common warnings, -Wextra → enable extra warnings, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants