MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / objcSelectorForSwiftInit

Function objcSelectorForSwiftInit

src/resolution/swift-objc-bridge.ts:117–147  ·  view source on GitHub ↗
(
  externalLabels: (string | null)[],
  internalNames: string[],
  explicitObjcName?: string | null
)

Source from the content-addressed store, hash-verified

115 * passed via `internalNames`.
116 */
117export function objcSelectorForSwiftInit(
118 externalLabels: (string | null)[],
119 internalNames: string[],
120 explicitObjcName?: string | null
121): string | null {
122 if (explicitObjcName) return explicitObjcName;
123
124 if (externalLabels.length === 0) {
125 return 'init';
126 }
127
128 const [firstExt, ...restExt] = externalLabels;
129 const [firstInt] = internalNames;
130 // Use the internal name when external is "_"; ObjC needs *some* keyword,
131 // and Swift's auto-bridger uses the parameter's local name in this case.
132 const firstLabel =
133 firstExt === null || firstExt === '_' || firstExt === ''
134 ? firstInt
135 : firstExt;
136 if (!firstLabel) return null;
137
138 const firstKeyword = `initWith${capFirst(firstLabel)}:`;
139 const restKeywords = restExt
140 .map((label, idx) => {
141 const internal = internalNames[idx + 1];
142 const name = label && label !== '_' ? label : internal ?? '';
143 return `${name}:`;
144 })
145 .join('');
146 return firstKeyword + restKeywords;
147}
148
149/**
150 * Compute the bridged ObjC getter + setter for a Swift `@objc` property.

Callers 1

Calls 2

capFirstFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected