Access objective-c Struct from Swift

I am working on an ios application that has a combination of fast and obj code. One of my obj-c model classes defines a structure containing strings to help convert to a dictionary and vice versa. I have a bridge header setting, and I can access the methods defined in the objective-c class in the quick access class. I cannot figure out how to access a static column to get property rows. Here is a snippet of my .h and .m files:

OrderItem.h

extern const struct OrderItemAttributes {
    __unsafe_unretained NSString *created;
    __unsafe_unretained NSString *created_by_id;
    __unsafe_unretained NSString *device_deleted;
} OrderItemAttributes;

@interface OrderItem : NSManagedObject {}
@property (nonatomic, strong) NSDate* created;
@end

OrderItem.m

const struct OrderItemAttributes OrderItemAttributes = {
    .created = @"created",
    .created_by_id = @"created_by_id",
    .device_deleted = @"device_deleted",
};

@implementation OrderItem
@dynamic created;
@end

I thought I would just use

OrderItem.OrderItemAttributes.created

to access attribute strings, but swift does not accept this syntax. Is there a way to do what I want without major changes to my objective-c code?

+4
1

OrderItemAttributes OrderItem. :

var foo: NSString = OrderItemAttributes.created.takeUnretainedValue()

, , , OrderItemAttributes ; . , . , 'Struct' :

extern const struct OrderItemAttributesStruct {
    __unsafe_unretained NSString *created;
    __unsafe_unretained NSString *created_by_id;
    __unsafe_unretained NSString *device_deleted;
} OrderItemAttributes;
+1

Source: https://habr.com/ru/post/1618013/


All Articles