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

Objective-C Promises crashes in SwiftUI previews #189

Open
paulb777 opened this issue Jun 17, 2022 · 3 comments
Open

Objective-C Promises crashes in SwiftUI previews #189

paulb777 opened this issue Jun 17, 2022 · 3 comments

Comments

@paulb777
Copy link
Member

When statically linked, the Promises categories don't get linked and apps crash in Swift UI previews.

A workaround may be to add a symbol to the category implementation files that is referenced from a non-category file.

See firebase/firebase-ios-sdk#8005 and firebase/firebase-ios-sdk#9916

@johndpope
Copy link

johndpope commented Aug 30, 2022

I'm attempting to use firebase analytics with (existing) bazel project - (not swiftui)
and it seems what you're describing is root of my problem. I linked below.

firebase/firebase-ios-sdk#6115

My hacked categories to inform static library ...

https://gist.github.com/wweevv-johndpope/fad4feb6f108c3df56033f28799d1d4c

apple_dynamic_xcframework_import(
    name = "FBLPromisesXCFramework",
    library_identifiers = {
        "ios_device": "ios-arm64",
        "ios_simulator": "ios-arm64_x86_64-simulator",
    },
    xcframework_imports = glob(["FBLPromises.xcframework/**"] ),
)

Screen Shot 2022-08-31 at 9 10 20 am

I have the categories -

//  FBLPromise+Extension.h
#if __has_include(<FBLPromises/FBLPromises.h>)
#import <FBLPromises/FBLPromises.h>
#else
#import "FBLPromises.h"
#endif
#import <Foundation/Foundation.h>

@interface FBLPromise (Extension)

@property(nonatomic, readonly) NSHTTPURLResponse *HTTPResponse;
@property(nonatomic, readonly) NSData *HTTPBody;

- (instancetype)initWithResponse:(NSHTTPURLResponse *)response HTTPBody:(NSData *)body;

@end
//  FBLPromise+Extension.m
#import "FBLPromises.h"
#import <Foundation/Foundation.h>

@implementation FBLPromise (Extension)
+ (NSData *)HTTPBody {
    return nil;
}

- (NSData *)HTTPBody {
    return nil;
}

+ (void)setHTTPBody:(NSData *)data {
}

- (void)setHTTPBody:(NSData *)data {
}

+ (NSHTTPURLResponse *)HTTPResponse {
    return nil;
}

- (NSHTTPURLResponse *)HTTPResponse {
    return nil;
}

+ (void)setHTTPResponse:(NSHTTPURLResponse *)data {
}

- (void)setHTTPResponse:(NSHTTPURLResponse *)data {
}

+ (instancetype)initWithResponse:(NSHTTPURLResponse *)response HTTPBody:(nullable NSData *)body {
    return nil;
}

- (instancetype)initWithResponse:(NSHTTPURLResponse *)response HTTPBody:(nullable NSData *)body {
    return nil;
}
@end


 

but my attempts to inject these into the mix haven't been fruitful.

objc_library(
    name = "FBLPromises",
    deps = ["FBLPromisesXCFramework"],
    enable_modules = True,
    module_name = "FBLPromises",
    visibility = ["//visibility:public"],
     srcs = glob([
        "FBLPromises/Sources/*.m",
        "FBLPromises/Sources/*.h",
    ]),
    hdrs = glob([
        "FBLPromises/PublicHeaders/*.h",
    ]),
    includes = [
       "FBLPromises/PublicHeaders", 
    ],

)

@sethdeckard
Copy link

I can confirm the behavior reported in this issue. Switching this over to be built as a framework instead of linked as a static lib resolves the issue and allows SwiftUI previews to work without crashing.

@akshaynhegde
Copy link

Is there a resolution here? I am facing the same issue with Xcode 15.3

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

4 participants