[ObjC] Provide NSCopying on all GPB*Descriptor objects.
PiperOrigin-RevId: 505999766
diff --git a/objectivec/GPBDescriptor.m b/objectivec/GPBDescriptor.m
index 4eb6533..2fb7712 100644
--- a/objectivec/GPBDescriptor.m
+++ b/objectivec/GPBDescriptor.m
@@ -207,6 +207,13 @@
[super dealloc];
}
+// No need to provide -hash/-isEqual: as the instances are singletons and the
+// default from NSObject is fine.
+- (instancetype)copyWithZone:(__unused NSZone *)zone {
+ // Immutable.
+ return [self retain];
+}
+
- (void)setupOneofs:(const char **)oneofNames
count:(uint32_t)count
firstHasIndex:(int32_t)firstHasIndex {
@@ -325,10 +332,6 @@
return result;
}
-- (instancetype)copyWithZone:(__unused NSZone *)zone {
- return [self retain];
-}
-
- (GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber {
for (GPBFieldDescriptor *descriptor in fields_) {
if (GPBFieldNumber(descriptor) == fieldNumber) {
@@ -415,6 +418,11 @@
return [package_ hash];
}
+- (instancetype)copyWithZone:(__unused NSZone *)zone {
+ // Immutable.
+ return [self retain];
+}
+
@end
@implementation GPBOneofDescriptor
@@ -440,6 +448,13 @@
[super dealloc];
}
+// No need to provide -hash/-isEqual: as the instances are singletons and the
+// default from NSObject is fine.
+- (instancetype)copyWithZone:(__unused NSZone *)zone {
+ // Immutable.
+ return [self retain];
+}
+
- (NSString *)name {
return (NSString *_Nonnull)@(name_);
}
@@ -617,6 +632,13 @@
[super dealloc];
}
+// No need to provide -hash/-isEqual: as the instances are singletons and the
+// default from NSObject is fine.
+- (instancetype)copyWithZone:(__unused NSZone *)zone {
+ // Immutable.
+ return [self retain];
+}
+
- (GPBDataType)dataType {
return description_->dataType;
}
@@ -881,6 +903,13 @@
[super dealloc];
}
+// No need to provide -hash/-isEqual: as the instances are singletons and the
+// default from NSObject is fine.
+- (instancetype)copyWithZone:(__unused NSZone *)zone {
+ // Immutable.
+ return [self retain];
+}
+
- (BOOL)isClosed {
return (flags_ & GPBEnumDescriptorInitializationFlag_IsClosed) != 0;
}
@@ -1082,6 +1111,8 @@
[super dealloc];
}
+// No need to provide -hash/-isEqual: as the instances are singletons and the
+// default from NSObject is fine.
- (instancetype)copyWithZone:(__unused NSZone *)zone {
// Immutable.
return [self retain];