You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func doSomething(foo: UnsafeMutablePointer<Foo>, bar: Int32)
295
+
func doSomething(to foo: UnsafeMutablePointer<Foo>, bar: Int32)
296
296
```
297
297
298
298
An underscore can be used in place of an empty parameter label, as in Swift.
@@ -430,4 +430,86 @@ Although enumerators always have global scope in C, they are often imported as m
430
430
431
431
_Currently, `swift_name` does not even allow importing an enum case as a member of the enum type itself, even if the enum is not recognized as an `@objc` enum, error code enum, or option set (i.e. the situation where a case is imported as a global constant)._
432
432
433
+
434
+
### Fields of structs and unions; Objective-C properties
435
+
436
+
The `swift_name` attribute can be applied to rename a struct or union field or an Objective-C property (whether on a class or a protocol). The value of the attribute must be a valid Swift identifier.
The `swift_name` attribute can be used to give an Objective-C method a custom name. The value of the attribute must be a full Swift function name, including parameter labels.
func doSomethingImportant(to foo: UnsafeMutablePointer<Foo>, bar: Int32)
464
+
```
465
+
466
+
As with functions, an underscore can be used to represent an empty parameter label.
467
+
468
+
Methods that follow the NSError out-parameter convention may provide one fewer parameter label than the number of parameters in the original method to indicate that a parameter should be dropped, but they do not have to. The `swift_error` attribute is still respected even when using a custom name for purposes of transforming an NSError out-parameter and the method return type.
A base name of "init" can be used on a *class* method that returns `instancetype` or the containing static type in order to import that method as an initializer. Any other custom name *prevents* a class method from being imported as an initializer even if it would normally be inferred as one.
A no-argument method imported as an initializer can be given a dummy argument label to disambiguate it from the no-argument `init()`, whether the method is an init-family instance method or a factory class method in Objective-C.
497
+
498
+
```objc
499
+
- (instancetype)initSafely
500
+
__attribute__((swift_name("init(safe:)")));
501
+
+ (instancetype)makeDefaultAction
502
+
__attribute__((swift_name("init(default:)")));
503
+
```
504
+
505
+
```swift
506
+
init(safe: ())
507
+
init(default: ())
508
+
```
509
+
510
+
A custom name on an instance method with one of Objective-C's subscript selectors (`objectAtIndexedSubscript:`, `objectForKeyedSubscript:`, `setObject:atIndexedSubscript:`, or `setObject:forKeyedSubscript:`) prevents that method from being imported as a subscript or used as the accessor for another subscript.
511
+
512
+
_Currently, this only works if *both* methods in a read/write subscript are given custom names; if just one is, a read/write subscript will still be formed. A read-only subscript only has one method to rename._
0 commit comments