Introduction to the function naming method of Obj-c

Source: Internet
Author: User
Tags bool

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/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.