ZXIErrors.mm 887 B

12345678910111213141516171819202122232425
  1. // Copyright 2023 KURZ Digital Solutions GmbH
  2. //
  3. // SPDX-License-Identifier: Apache-2.0
  4. #import "ZXIErrors.h"
  5. void SetNSError(NSError *__autoreleasing _Nullable* error,
  6. NSInteger code,
  7. const char* message) {
  8. if (error == nil) {
  9. return;
  10. }
  11. NSString *errorDescription = @"Unknown C++ error";
  12. if (message && strlen(message) > 0) {
  13. errorDescription = [NSString stringWithUTF8String: message];
  14. if (errorDescription == nil) {
  15. errorDescription = [NSString stringWithCString: message
  16. encoding: NSASCIIStringEncoding];
  17. }
  18. }
  19. NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: errorDescription };
  20. *error = [NSError errorWithDomain:ZXIErrorDomain
  21. code:code
  22. userInfo:userInfo];
  23. }