From ca0dd9bb5c095b5c57ac4d53c8f764954fcec7eb Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Thu, 22 Sep 2022 18:51:29 +0200 Subject: [PATCH] [darwin-framework-tool] Just send a message to read the MTRErrorHolder value instead of duplicating the class interface (#22811) --- .../commands/common/MTRError.mm | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/examples/darwin-framework-tool/commands/common/MTRError.mm b/examples/darwin-framework-tool/commands/common/MTRError.mm index 7ad3138802da6f..c393682a7a84e0 100644 --- a/examples/darwin-framework-tool/commands/common/MTRError.mm +++ b/examples/darwin-framework-tool/commands/common/MTRError.mm @@ -25,25 +25,6 @@ #import #import -// Stolen for now from the framework, need to export this properly. -@interface DFTErrorHolder : NSObject -@property (nonatomic, readonly) CHIP_ERROR error; -@end - -@implementation DFTErrorHolder - -- (instancetype)initWithError:(CHIP_ERROR)error -{ - if (!(self = [super init])) { - return nil; - } - - _error = error; - return self; -} - -@end - CHIP_ERROR MTRErrorToCHIPErrorCode(NSError * error) { if (error == nil) { @@ -64,8 +45,13 @@ CHIP_ERROR MTRErrorToCHIPErrorCode(NSError * error) if (error.userInfo != nil) { id underlyingError = error.userInfo[@"underlyingError"]; - if (underlyingError != nil && [underlyingError isKindOfClass:[DFTErrorHolder class]]) { - return ((DFTErrorHolder *) underlyingError).error; + if (underlyingError != nil) { + NSValue * chipErrorValue = [underlyingError valueForKey:@"error"]; + if (chipErrorValue != nil) { + CHIP_ERROR chipError; + [chipErrorValue getValue:&chipError]; + return chipError; + } } }