Out of interest, how are method names stored in memory in compiled Objective-C? The main reason of interest is understanding dynamic typing better.
Thanks in advance!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The source for the runtime is available, btw, if you really want to go deep.
In short; method names — their selectors — are stored as C strings in the mach-o of the binary. I.e. if you have a method
-(void)foo:(int)a bar:(int)b;, there will be a selectorfoo:bar:string in the mach-o.Type encoding information is also stored in a different segment of the mach-o file. That type information — for which there is API in the runtime to retrieve it — describes the type of the return value and arguments to the method.
Note that the type information is incomplete. Note also that using the type information to figure out how to generically encode/decode the arguments to and return value from a method is a downright pain.