Skip to content

Commit b5d862f

Browse files
Merge pull request #2705 from DataDog/nogorodnikov/support-generated-rum-objc-rename
Add support of renaming Objective-C runtime classes for generated RUM models Co-authored-by: 0xnm <nikita.ogorodnikov@datadoghq.com>
2 parents abfc71b + 7ccef78 commit b5d862f

5 files changed

Lines changed: 48 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
- [IMPROVEMENT] Rename `DDRUMErrorEventErrorMeta` to `DDRUMErrorEventErrorMetaInfo`, add support of custom Objective-C runtime names for generated RUM models. See [#2705][]
4+
35
# 3.7.0 / 18-02-2026
46

57
- [FEATURE] Add evaluation logging to `DatadogFlags` module. See [#2646][]
@@ -1057,6 +1059,7 @@ Release `2.0` introduces breaking changes. Follow the [Migration Guide](MIGRATIO
10571059
[#2674]: https://github.com/DataDog/dd-sdk-ios/pull/2674
10581060
[#2676]: https://github.com/DataDog/dd-sdk-ios/pull/2676
10591061
[#2688]: https://github.com/DataDog/dd-sdk-ios/pull/2688
1062+
[#2705]: https://github.com/DataDog/dd-sdk-ios/pull/2705
10601063

10611064
[@00fa9a]: https://github.com/00FA9A
10621065
[@britton-earnin]: https://github.com/Britton-Earnin

DatadogRUM/Sources/DataModels/RUMDataModels+objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2261,7 +2261,7 @@ public enum objc_RUMErrorEventErrorHandling: Int {
22612261
case unhandled
22622262
}
22632263

2264-
@objc(DDRUMErrorEventErrorMeta)
2264+
@objc(DDRUMErrorEventErrorMetaInfo)
22652265
@objcMembers
22662266
@_spi(objc)
22672267
public class objc_RUMErrorEventErrorMeta: NSObject {

tools/rum-models-generator/Sources/CodeGeneration/Print/ObjcInteropPrinter.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ import Foundation
3636
/// }
3737
///
3838
public class ObjcInteropPrinter: BasePrinter, CodePrinter {
39-
public init(objcTypeNamesPrefix: String) {
39+
public init(
40+
objcTypeNamesPrefix: String,
41+
objcRuntimeNameOverrides: [String: String] = [:]
42+
) {
4043
self.objcTypeNamesPrefix = objcTypeNamesPrefix
44+
self.objcRuntimeNameOverrides = objcRuntimeNameOverrides
4145
}
4246

4347
// MARK: - CodePrinter
@@ -52,6 +56,9 @@ public class ObjcInteropPrinter: BasePrinter, CodePrinter {
5256

5357
/// The prefix used for types exposed to Obj-c.
5458
private let objcTypeNamesPrefix: String
59+
/// Overrides for generated `@objc(...)` runtime names.
60+
/// Keys are generated type names (e.g. `objc_RUMErrorEventErrorMeta`), values are runtime names (e.g. `DDRUMErrorEventMeta`).
61+
private let objcRuntimeNameOverrides: [String: String]
5562

5663
func print(objcInteropTypes: [ObjcInteropType]) throws -> String {
5764
reset()
@@ -81,7 +88,7 @@ public class ObjcInteropPrinter: BasePrinter, CodePrinter {
8188
private func print(objcInteropRootClass: ObjcInteropRootClass) throws {
8289
let className = objcTypeNamesPrefix + objcInteropRootClass.objcTypeName
8390
writeEmptyLine()
84-
writeLine("@objc(\(className.objcNaming))")
91+
writeLine("@objc(\(objcRuntimeName(for: className)))")
8592
writeLine("@objcMembers")
8693
writeLine("@_spi(objc)")
8794
writeLine("public class \(className): NSObject {")
@@ -123,7 +130,7 @@ public class ObjcInteropPrinter: BasePrinter, CodePrinter {
123130
}
124131

125132
writeEmptyLine()
126-
writeLine("@objc(\(objcTypeName.objcNaming))")
133+
writeLine("@objc(\(objcRuntimeName(for: objcTypeName)))")
127134
writeLine("@objcMembers")
128135
writeLine("@_spi(objc)")
129136
writeLine("public class \(objcTypeName): NSObject {")
@@ -161,7 +168,7 @@ public class ObjcInteropPrinter: BasePrinter, CodePrinter {
161168
let className = objcTypeNamesPrefix + objcInteropNestedTransitiveClass.objcTypeName
162169
let rootClassName = objcTypeNamesPrefix + objcInteropNestedTransitiveClass.objcRootClass.objcTypeName
163170
writeEmptyLine()
164-
writeLine("@objc(\(className.objcNaming))")
171+
writeLine("@objc(\(objcRuntimeName(for: className)))")
165172
writeLine("@objcMembers")
166173
writeLine("@_spi(objc)")
167174
writeLine("public class \(className): NSObject {")
@@ -203,7 +210,7 @@ public class ObjcInteropPrinter: BasePrinter, CodePrinter {
203210
let managesOptionalEnum = objcInteropNestedEnum.parentProperty.bridgedSwiftProperty.isOptional
204211
let objcEnumOptionality = managesOptionalEnum ? "?" : ""
205212
writeEmptyLine()
206-
writeLine("@objc(\(enumName.objcNaming))")
213+
writeLine("@objc(\(objcRuntimeName(for: enumName)))")
207214
writeLine("@_spi(objc)")
208215
writeLine("public enum \(enumName): Int {")
209216
indentRight()
@@ -254,7 +261,7 @@ public class ObjcInteropPrinter: BasePrinter, CodePrinter {
254261
}
255262

256263
writeEmptyLine()
257-
writeLine("@objc(\(className.objcNaming))")
264+
writeLine("@objc(\(objcRuntimeName(for: className)))")
258265
writeLine("@objcMembers")
259266
writeLine("@_spi(objc)")
260267
writeLine("public class \(className): NSObject {")
@@ -574,6 +581,10 @@ public class ObjcInteropPrinter: BasePrinter, CodePrinter {
574581

575582
// MARK: - Generating names
576583

584+
private func objcRuntimeName(for generatedObjcTypeName: String) -> String {
585+
objcRuntimeNameOverrides[generatedObjcTypeName] ?? generatedObjcTypeName.objcNaming
586+
}
587+
577588
private func objcInteropTypeName(for objcType: ObjcInteropType) throws -> String {
578589
switch objcType {
579590
case is ObjcInteropNSNumber:

tools/rum-models-generator/Sources/rum-models-generator/GenerateRUMModels.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ internal func generateRUMSwiftModels(from schema: URL) throws -> String {
4343

4444
internal func generateRUMObjcInteropModels(from schema: URL, skip typesToSkip: Set<String>) throws -> String {
4545
let generator = ModelsGenerator()
46+
let objcRuntimeNameOverrides = [
47+
"objc_RUMErrorEventErrorMeta": "DDRUMErrorEventErrorMetaInfo"
48+
]
4649

4750
let template = OutputTemplate(
4851
header: """
@@ -66,7 +69,10 @@ internal func generateRUMObjcInteropModels(from schema: URL, skip typesToSkip: S
6669
6770
"""
6871
)
69-
let printer = ObjcInteropPrinter(objcTypeNamesPrefix: "objc_")
72+
let printer = ObjcInteropPrinter(
73+
objcTypeNamesPrefix: "objc_",
74+
objcRuntimeNameOverrides: objcRuntimeNameOverrides
75+
)
7076

7177
return try generator
7278
.generateCode(from: schema)

tools/rum-models-generator/Tests/CodeGenerationTests/Print/ObjcInteropPrinterTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,26 @@ final class ObjcInteropPrinterTests: XCTestCase {
129129
XCTAssertEqual(expected, actual)
130130
}
131131

132+
func testPrintingObjcInteropWithCustomObjcRuntimeNameOverride() throws {
133+
let fooStruct = SwiftStruct(
134+
name: "Foo",
135+
comment: nil,
136+
properties: [],
137+
conformance: []
138+
)
139+
140+
let objcInteropTypes = try SwiftToObjcInteropTypeTransformer()
141+
.transform(swiftTypes: [fooStruct])
142+
let objcInteropPrinter = ObjcInteropPrinter(
143+
objcTypeNamesPrefix: "objc_",
144+
objcRuntimeNameOverrides: ["objc_Foo": "DDCustomFoo"]
145+
)
146+
let output = try objcInteropPrinter.print(objcInteropTypes: objcInteropTypes)
147+
148+
XCTAssertTrue(output.contains("@objc(DDCustomFoo)"))
149+
XCTAssertFalse(output.contains("@objc(DDFoo)"))
150+
}
151+
132152
func testPrintingObjcInteropForSwiftStructWithIntProperties() throws {
133153
let fooStruct = SwiftStruct(
134154
name: "Foo",

0 commit comments

Comments
 (0)