How to call a method in Objective-C? [duplicate] - objective-c

This question already has answers here:
How can I call a method in Objective-C?
(8 answers)
Closed 9 years ago.
I am just starting out in ios and am trying to make user defined functions...
my code:
-(void) testFunction{
//has self. calls
}
-(IBAction)button:(id)sender {
testFunction();
}
I get the warning: Implicit declaration of function is invalid in C99
What am I doing wrong? Or what do I have to add to my code?

In Objective-C you cant write testFunction(). You send 'messages' and you can do this via
[self testFunction]

Related

Getting class name in SWIFT equivalent to Objective C [self class]? [duplicate]

This question already has answers here:
Get class name of object as string in Swift
(32 answers)
Closed 3 years ago.
I am using the following syntax to debug my Objective C code, getting the class name. What is the equivalent in SWIFT?
NSlog (#"Classe = %#",[self class]);
You can use print("Class = \(type(of: self))" in Swift.

What does (void (^)(BOOL supported)) mean? [duplicate]

This question already has answers here:
Caret in objective C
(3 answers)
Closed 7 years ago.
as I am working myself into some new code, I came across a thing, where I couldnt find any explanation for in the web so far. So hopefully you can give me one.
I have this method signature in Objective-C code:
-(void) supportsUrl: (NSString*) url callback:(void (^)(BOOL supported)) callback;
Can someone please tell me what it is about in the last parameter?
Thanks a lot!
It is a block that takes a BOOL argument and returns void. See the documentation for more info on the syntax.
When invoking this method, you can provide a callback through this block. This will let you submit code to be executed after the method has run.
For example:
[self supportsUrl:#"http://www.google.com" callback:^(BOOL supported){
if (supported) NSLog(#"Yay, supported");
else NSLog(#"Nay, not supported");
}];

Is there an ObjC macro or function to get all the argument values received by a method? [duplicate]

This question already has answers here:
Pass all arguments of a method into NSLog
(2 answers)
Closed 8 years ago.
I know that NSStringFromSelector(_cmd) gives the name of the current method. I use that in a debugging macro to print what method I'm in. I would like to also get the method's arguments as strings so I can print them too. I'm thinking of something like *argv[] in C.
Is there any built-in facility for that?
Yes, c++ (and Objective-C) support va_list.
Do something like this:
- (void)do:(va_list)args
{
// do something with all your args
}
And use it like this:
[self do:#"foo", #"bar"]

objective c method asterisk [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Asterisk in parenthesis in Objective-C… What does it mean?
does anyone can find some resource or detail explanation about following code
-(void) add:(Cal *)c;
I am very new to obj-c.what does asterisk means in that code?
Thanks.
It means that the argument for the method is a pointer to an instance of a "Cal" object.

Class methods and self keyword in objective-c [duplicate]

This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
“Invalid use of 'this' in non-member function” in objective-c context?
If I use the keyword self inside a class method:
+ (id) myMetho
{
self ...
}
Does it refer to the class or to the current instance ?
In short, it represents the class. For a longer answer, have a look here
self just means "the class you are in"