google / promises

Promises is a modern framework that provides a synchronization construct for Swift and Objective-C.
Apache License 2.0
3.81k stars 296 forks source link

Objective-C Promises crashes in SwiftUI previews #189

Open paulb777 opened 2 years ago

paulb777 commented 2 years ago

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 https://github.com/firebase/firebase-ios-sdk/issues/8005 and https://github.com/firebase/firebase-ios-sdk/issues/9916

johndpope commented 2 years ago

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.

https://github.com/firebase/firebase-ios-sdk/issues/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 commented 1 year ago

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 commented 5 months ago

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