IBActions foo and foo:
-
30-09-2019 - |
Question
In Interface Builder I in Library->Classes when I select a class that I made in XCode, then display the Actions, I can see two with the same name:
foo
foo:
What is the difference between these two foos?
Solution
foo
is a method that doesn't accept any arguments. foo:
passes an argument or arguments into its method.
Example:
-(IBAction)foo;
will be shown as foo
in IB.
-(IBAction)foo:(id)sender;
will be shown as foo:
in IB.
I don't know why they have the same name, do you have them set that way?
OTHER TIPS
IB assumes if your creating the class files using IB that you will using the sender and so it creates the construct
-(IBAction)foo:(id)sender;
You usually will need info about the sender so I would stick with that construct. If you don't need the sender in your implementation, simply ignore it.
-(IBAction)foo:(id)sender {
[someObject doAMethod];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow