Skip to content

Commit 9aaea31

Browse files
authored
Add copy API to ExecuTorchValue (#10954)
1 parent 6f59e89 commit 9aaea31

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

extension/apple/ExecuTorch/Exported/ExecuTorchValue.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ typedef float ExecuTorchFloatValue
5050
*/
5151
NS_SWIFT_NAME(Value)
5252
__attribute__((deprecated("This API is experimental.")))
53-
@interface ExecuTorchValue : NSObject
53+
@interface ExecuTorchValue : NSObject <NSCopying>
5454

5555
/**
5656
* The tag that indicates the dynamic type of the value.
@@ -208,6 +208,12 @@ __attribute__((deprecated("This API is experimental.")))
208208
+ (instancetype)valueWithDouble:(ExecuTorchDoubleValue)value
209209
NS_SWIFT_NAME(init(_:));
210210

211+
/**
212+
* Returns a copy of the value.
213+
*
214+
* @return A new ExecuTorchValue instance that is a duplicate of the current value.
215+
*/
216+
- (instancetype)copy;
211217

212218
/**
213219
* Determines whether the current Value is equal to another Value.

extension/apple/ExecuTorch/Exported/ExecuTorchValue.mm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ - (instancetype)initWithTag:(ExecuTorchValueTag)tag
5757
return self;
5858
}
5959

60+
- (instancetype)copy {
61+
return [self copyWithZone:nil];
62+
}
63+
64+
- (instancetype)copyWithZone:(nullable NSZone *)zone {
65+
return [[ExecuTorchValue allocWithZone:zone] initWithTag:_tag
66+
value:[_value copyWithZone:zone]];
67+
}
68+
6069
- (ExecuTorchValueTag)tag {
6170
return _tag;
6271
}

0 commit comments

Comments
 (0)