Skip to content

Commit 1bb666a

Browse files
committed
[docs] CToSwiftName: Add the section on ObjC properties
Fairly simple except in the few cases they aren't.
1 parent dfe0085 commit 1bb666a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/CToSwiftNameTranslation.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,29 @@ Additionally, typedefs for `void *` or `const void *` that are themselves annota
212212
If a typedef's underlying type is itself a "CF pointer" typedef, the "alias" typedef will be imported as a regular typealias, with the suffix "Ref" still dropped from its name (if present) unless doing so would conflict with another declaration in the same module as the typedef.
213213

214214

215+
## Objective-C Properties
216+
217+
By default, most property names are not transformed at all. However, if the getter of a property overrides a superclass or adopted protocol method that is also a property accessor, the Swift name of the overridden accessor's property will be used for consistency. If there's more than one such name, one is chosen arbitrarily.
218+
219+
Properties with the type `BOOL` or `Boolean` use the name of the getter as the name of the Swift property by default, rather than the name of the property in Objective-C. This accounts for a difference in Swift and Objective-C naming conventions for boolean properties that use "is".
220+
221+
```objc
222+
@property(getter=isContrivedExample) BOOL contrivedExample;
223+
@property BOOL hasAnotherForm;
224+
```
225+
226+
```swift
227+
var isContrivedExample: Bool { get set }
228+
var hasAnotherForm: Bool { get set }
229+
```
230+
231+
_This rule should probably have applied to C's native `bool` as well._
232+
233+
A property declaration with the `SwiftImportPropertyAsAccessors` API note will not be imported at all, and its accessors will be imported as methods. Additionally, properties whose names start with "accessibility" in the NSAccessibility protocol are always imported as methods, as are properties whose names start with "accessibility" in an `@interface` declaration (class or category) that provides the adoption of NSAccessibility.
234+
235+
_Objective-C code has historically not been consistent about whether the NSAccessibility declarations should be considered properties and therefore the Swift compiler chooses to import them as methods, as a sort of lowest common denominator._
236+
237+
215238
## `swift_private`
216239

217240
The `swift_private` Clang attribute prepends `__` onto the base name of any declaration being imported except initializers. For initializers with no arguments, a dummy `Void` argument with the name `__` is inserted; otherwise, the label for the first argument has `__` prepended. This transformation takes place after any other name manipulation, unless the declaration has a custom name. It will not occur if the declaration is an override; in that case the name needs to match the overridden declaration.

0 commit comments

Comments
 (0)