I have a question about swift function name rule. As I tried in IDA Pro to analyze a iOS app (Maybe OS X is the same case) written in swift, such as swift-2048, I got function n
Swift is using Name Mangling
for the naming of methods,classes..... I came across this article which describes about swift name mangling. Section about mangling is shown below.
Swift keeps metadata about functions (and more) in their respective symbols, which is called name mangling. This metadata includes the function’s name (obviously), attributes, module name, argument types, return type, and more. Take this for example:
class Shape{
func numberOfSides() -> Int {
return 5
}
}
The mangled name for the simpleDescription method is _TFC9swifttest5Shape17simpleDescriptionfS0_FT_Si
.
Here’s the breakdown:
_T – The prefix for all Swift symbols. Everything will start with this.
F – Function.
C – Function of a class. (method)
9swifttest – The module name, with a prefixed length.
5Shape – The class name the function belongs to, again, with a prefixed length.
17simpleDescription – The function name.
f – The function attribute. In this case it’s ‘f’, which is just a normal function. We’ll get to that in a minute.
S0_FT – I’m not exactly sure what this means, but it appears to mark the start of the arguments and return type.
‘_’ – This underscore separates the argument types from the return type. Since the function takes no arguments, it comes directly after S0_FT.
S – This is the beginning of the return type. The ‘S’ stands for Swift; the return type is a Swift builtin type. The next character determines the type.
i – This is the Swift builtin type. A lowercase ‘I’, which stands for Int.
Excerpt from: Inside Swift
looks like actual link is broken, find mirror here