For a friend who used to do C # or Java development, the first contact with iOS development, Obj-c's function naming method may feel very unaccustomed.
In particular, open APPDELEGATE.M, the code of the eye is unexpectedly:
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
{
Override point for customization after application launch.
return YES;
}
I do not know if there will be friends and I had the same feeling--God, this is too long!!!
In fact, in Obj-c, the function name of the above function should be:
-(BOOL) Application:didfinishlaunchingwithoptions:
Application and launchoptions followed by parentheses are parameters that are used within the function.
We can interpret this function as "Application: Completing Startup Usage options:".
The parameters that follow the application colon are the name of the application itself.
The arguments that follow the "Finish startup using option" Colon are the name of the startup option.
Here I used two "as the name implies", right is the name as it is! The way the Obj-c function is named is a bit like a natural language, and I'm sure everyone will be as familiar as I am with the gradual deepening of iOS development, which will become more and more adaptable and even like this naming style.
Here's another example, if we define an addition function in Java, we'll probably use the following method:
/**
* Calculates the result of A+b
* @param a
* @param b
* @return returns A+B and/or public
int Add (int a, int b) {
retur n A + b;
}
When you define a function in Java, we usually get used to writing a simple annotation so that we can use the smart hints of eclipse to see what these parameters mean in other locations in the program, and you can also use the Javadoc tool to generate the program documentation. It's very convenient and meaningful!
And what are we going to do in obj-c? First, define a function, the following code:
-(Nsinteger) AddA: (Nsinteger) a WITHB: (Nsinteger) b {
return a + B;
}
When you call the function, the Xcode prompt looks like this:
[Self AddA: (Nsinteger) WITHB: (Nsinteger)];
At this point, we can interpret this sentence as "plus A and B", do not feel more easy to understand some ah? should be, hehe.
In Obj-c, if you develop a good function naming habit. Believe that as time goes on, you will find that there will be less and fewer notes to write. Although there are no smart hints similar to eclipse in Xcode, this does not prevent us from seeing clearly what each function does, what parameters they need, and what each argument should be.
Let's enjoy a happy iOS development tour
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/C/