C-style struct in Objc not importing to Swift

484 Views Asked by At

The problem I'm encountering, and absolutely not understanding, is why can my Swift code not access an bridged C-style struct import from objective-c when a NSString pointer is contained, whereas the struct is visible when then NSString is replaced with a char *.

For example, when I've got the following defined in my Foo.h file:

typedef struct {
    NSString* value;
    SomeEnum unit;
} SomeMeasurement;

I get an error of Value of Type ... has no member Measurement (from the parental class) at compile time.

Whereas when my struct is the following:

typedef struct {
    char* value;
    SomeEnum unit;
} SomeMeasurement;

Things compile as expected (even if char unusable for my current needs). The fact that that small change allows for this struct to be "seen" by Swift is totally perplexing me, since it means it's (probably) not an issue with a file in bridging header or something of that sort.

Also, if I replace NSString with NSMutableData, the problem persists, and the struct cannot be seen.

0

There are 0 best solutions below