PostHog / posthog-ios

PostHog iOS SDK
https://posthog.com/docs/libraries/ios
MIT License
35 stars 41 forks source link

Swift package testing #51

Closed bddq closed 11 months ago

bddq commented 1 year ago

Thanks for your great product.

I'm using PostHog package as a dependency of another package. The other package has basic Swift tests that are run with swift test command on CI.

With the PostHog dependency, I got an error because your package references UIKit. So I cannot test anymore my package.

Is it possible to split the PostHog package to have core classes in one target and UI classes in another?

Let me know if I can help more.

Regards, Benoit

marandaneto commented 12 months ago

@bddq what can be done is to check if UIKit is available with compile flags and only then allow the code to be run, do you where exactly this is happening?

bddq commented 12 months ago

When I run swift test I got the following output:

benoit@Benoits-M1 posthog-ios % swift test
Building for debugging...
In file included from /Users/benoit/Developer/PostHog-origin/posthog-ios/PostHog/Internal/UIViewController+PHGScreen.m:1:
/Users/benoit/Developer/PostHog-origin/posthog-ios/PostHog/Internal/UIViewController+PHGScreen.h:7:12: error: cannot find interface declaration for 'UIViewController'
@interface UIViewController (PHGScreen)
           ^
/Users/benoit/Developer/PostHog-origin/posthog-ios/PostHog/Internal/UIViewController+PHGScreen.h:9:4: error: expected a type
+ (BOOL)isAppExtension;
   ^
/Users/benoit/Developer/PostHog-origin/posthog-ios/PostHog/Internal/UIViewController+PHGScreen.h:12:4: error: expected a type
+ (UIViewController *)phg_topViewController;
   ^
In file included from /Users/benoit/Developer/PostHog-origin/posthog-ios/PostHog/Internal/UIViewController+PHGScreen.m:3:
In file included from /Users/benoit/Developer/PostHog-origin/posthog-ios/PostHog/Classes/PHGPostHog.h:2:
/Users/benoit/Developer/PostHog-origin/posthog-ios/PostHog/Classes/PHGPostHogConfiguration.h:2:9: fatal error: 'UIKit/UIKit.h' file not found
#import <UIKit/UIKit.h>
        ^~~~~~~~~~~~~~~
4 errors generated.
/Users/benoit/Developer/PostHog-origin/posthog-ios/PostHog/Internal/PHGPostHogIntegration.m:3:9: fatal error: 'UIKit/UIKit.h' file not found
#import <UIKit/UIKit.h>
        ^~~~~~~~~~~~~~~
[4/24] Compiling PHGStoreKitCapturer.m
error: fatalError

I think we can use compile flags to ignore referenced files.

marandaneto commented 12 months ago

We're currently rewriting the iOS SDK as well and will take care of that in the next major.

marandaneto commented 11 months ago

Closed because of the new major version that should have addressed this use case https://github.com/PostHog/posthog-ios/pull/75