Skip to content

Commit f6129f1

Browse files
authored
Return retained objects from NSError constructors.
Differential Revision: D76491603 Pull Request resolved: pytorch/executorch#11630
1 parent f60f0e8 commit f6129f1

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

extension/apple/ExecuTorch/Exported/ExecuTorchError.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ NSString *ExecuTorchErrorDescription(ExecuTorchErrorCode code)
6363
* @return An NSError with ExecuTorchErrorDomain, the specified code, and a localized description.
6464
*/
6565
FOUNDATION_EXPORT
66+
NS_RETURNS_RETAINED
6667
__attribute__((deprecated("This API is experimental.")))
6768
NSError *ExecuTorchErrorWithCode(ExecuTorchErrorCode code)
6869
NS_SWIFT_NAME(Error(code:));
@@ -75,6 +76,7 @@ NSError *ExecuTorchErrorWithCode(ExecuTorchErrorCode code)
7576
* @return An NSError with ExecuTorchErrorDomain, the specified code, and a localized description.
7677
*/
7778
FOUNDATION_EXPORT
79+
NS_RETURNS_RETAINED
7880
__attribute__((deprecated("This API is experimental.")))
7981
NSError *ExecuTorchErrorWithCodeAndDescription(ExecuTorchErrorCode code, NSString * __nullable description)
8082
NS_SWIFT_NAME(Error(code:description:));

extension/apple/ExecuTorch/Exported/ExecuTorchError.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
}
5959

6060
NSError *ExecuTorchErrorWithCodeAndDescription(ExecuTorchErrorCode code, NSString * __nullable description) {
61-
return [NSError errorWithDomain:ExecuTorchErrorDomain
62-
code:code
63-
userInfo:@{
61+
return [[NSError alloc] initWithDomain:ExecuTorchErrorDomain
62+
code:code
63+
userInfo:@{
6464
NSLocalizedDescriptionKey:
6565
description.length > 0
6666
? [ExecuTorchErrorDescription(code) stringByAppendingFormat:@": %@", description]

0 commit comments

Comments
 (0)