I made an xcframework (in objective c) which is working fine in objective C but throws an error when using swift.
On debugging, I realized that it was breaking in swift because I was using assign.
I went through his answer: https://stackoverflow.com/a/4511004/10433835
where they say this
In most cases you'll want to use weak so you're not trying to access a deallocated object
I didn't quite get what assign does, but I don't think I am trying to access a deallocated object.
This is what I am doing
I have config with these properties
#import <Foundation/Foundation.h>
@interface Config : NSObject
@property(nonatomic, assign, readwrite) NSString *name;
@property(nonatomic, assign, readwrite) NSString *id;
@property(nonatomic, assign, readwrite) NSString *api;
@end
This is my Config.m file
@implementation Config
- (id)init {
if (self = [super init]) {
_api = @"https://api.xyz.in"
}
return self;
}
- (NSMutableDictionary *_Nonnull)configProperties {
if (!_name) {
[NSException raise:@"name" format:@"Room name cannot be null, please set room name"];
}
NSLog(@"Room name: %@", _name);
At this line it will throw Thread 1: EXC_BAD_ACCESS
NSLog(@" name: %@", _name);
if I remove assign, it won't throw any error
How am I calling it?
let config:Config = Config();
config.name = "varun_bindal";
let props = config.configProperties()
Can someone please explain me why using assign
in swift is crashing my code? and why not using it doesn't.