We all know that in Objective-c there are two ways to call a function:
- Sending a message
[obj meth]; - Call the
obj.meth;methodobj.meth;
I really want to learn how to call a method with one argument in the second way. If the first way with one argument [obj meth:arg]; , what will the second method look like? It was experimentally established that the javas trick
obj.meth(arg);
in objective-c does not work.
For example, I didn’t generate simple code:
#import "Cocoa/Cocoa.h" @interface QNObject: NSObject { int num; } @end @implementation QNObject - (int) num:(int)x //метод принимает int на вход { return 5; } @end int main(int argc, char *argv[]) { // NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - НЕ НУЖНО В ВЫСОКИХ ВЕРСИЯХ XCODE QNObject *o = [[QNObject alloc] init]; NSLog(@"%d", [o num:9]); //ПОСЫЛАНИЕ СООБЩЕНИЯ. РАБОТАЕТ НОРМАЛЬНО NSLog(@"%d", o.num(5)); // ВЫЗОВ МЕТОДА. ВЫДАЕТ ОШИБКУ // [o release]; - НЕ НУЖНО В ВЫСОКИХ ВЕРСИЯХ XCODE // [pool release]; - НЕ НУЖНО В ВЫСОКИХ ВЕРСИЯХ XCODE return 0; } How to rewrite it so that there is no mistake in the fifth line from the end?