Converting to Swift 3 renamed my own Objective-C method

The translation process is described in detail in

The relevant part for your question is (emphasis mine):

Prune a match for the enclosing type from the base name of a method so
long as the match starts after a verb. For example,

extension UIViewController {
  func dismissViewControllerAnimated(flag: Bool, completion: (() -> Void)? = nil)
}

becomes:

extension UIViewController {
  func dismissAnimated(flag: Bool, completion: (() -> Void)? = nil)
}

This pruning algorithm is – as far as I can see – implemented in
StringExtras.cpp (and uses a lot of heuristics),
and PartsOfSpeech.def
contains a list of words which are considered a verb, such as

VERB(dismiss)
VERB(read)
VERB(send)

but not VERB(sent). That explains why – simplifying your example slightly –

@interface DeliveryInfo : NSObject
-(void)readDeliveryInfoItems;
-(void)sentDeliveryInfoItems;
@end

becomes

open class DeliveryInfo : NSObject {
    open func readItems()
    open func sentDeliveryInfoItems()
}

The type name is pruned after the verb “read”, but not after the
non-verb “sent”. (You can verify that by changing the second method
name to sendDeliveryInfoItems which is then mapped to sendItems().)

You can override the mapping with NS_SWIFT_NAME:

-(void)readDeliveryInfoItems NS_SWIFT_NAME(readDeliveryInfoItems());

Leave a Comment