ios - Cannot callback NSError in block in release mode framework
问题描述
I have build a framework called myTool.framework only in Release Mode.
In this framework there is a function with a block callback:
// myTools.h
- (void)initServiceWithKey:(NSString * _Nullable)accessKey
complete:(void(^)(NSError *error, NSInteger roomType))complete;
// myTools.m
@property (nonatomic, copy) void (^complete)(NSError * error, NSInteger roomType);
@property (nonatomic, strong) NSError *error;
- (void)initServiceWithKey:(NSString * _Nullable)accessKey
complete:(void(^)(NSError *error, NSInteger roomType))complete {
balabala...
if (somethingWrong) {
self.error = [NSError errorWithDomain:@"Error Domain" code:-1 userInfo:nil];
if (self.complete) {
self.complete(self.error, -1);
return;
}
}
}
Then I use it in a demo like this:
[myToos sharedInstance] initServiceWithKey:@"123key" complete:^(NSError * _Nonnull error, NSInteger roomType) {
if (!error) {
#error always is nil here when run demo in release mode, roomType is fine.
}
}
When running demo in Debug I can get error normally, but error is always nil in Release as NSInteger is fine.
I already save the error and block as a singleton's property, It didn't work.
Why this and How can I solve this? Thanks