When you use a Swift API from Objective-C, the compiler typically performs a direct translation. For example, the Swift API func playSong(name: String)
is imported as - (void)playSong:(NSString *)name
in Objective-C.
However, there is one exception: When you use a Swift initializer in Objective-C, the compiler adds the text “initWith
” to the beginning of the method and properly capitalizes the first character in the original initializer.
For example, this Swift initializer init (songName: String, artist: String)
is imported as - (instancetype)initWithSongName:(NSString *)songName artist:(NSString *)artist
in Objective-C.