Crash when accessing property of a bridged Objective-C object via Swift

My application crashes when accessing a dictionary from a bridged objective-c object.

TestObject.h

@interface TestObject : NSObject

- (instancetype)initWithDictionary:(NSDictionary *)dictionary;

@property (nonatomic, assign) NSDictionary *dictionary;

@end

TestObject.m

@implementation TestObject

- (instancetype)initWithDictionary:(NSDictionary *)dictionary {
    self = [super init];
    if (self != nil) {
        self.dictionary = dictionary;
    }
    return self;
}

@end

Example.swift

var someDic = ["Key": "Value"]
let testObject = TestObject(dictionary: someDic)
        
// Crash
let objectDic = testObject.dictionary

Am I missing something?

Change assign to strong.

1 Like