[OC syntax overview] 3. Create an Instance Object

Source: Internet
Author: User
Creating objects Create object

There are two main ways to create an object. The first is the one you saw before: There are two main methods to create an object. The first type is as follows: Nsstring * mystring = [nsstring string];This is the more convenient automatic style. in this case, you are creating an autoreleased object, which we'll look at in more detail later. in your cases, though, you need to create an object using themanual style: the above method is more convenient and automatic. In this case, an automatically released object is created, and we will explore more details. In more cases, you need to manually create an object: Nsstring * mystring = [[nsstringalloc] init];This is a nested method call. the first is the alloc method called on nsstring itself. this is a relatively low-level call which reserves memory and instantiates an object. this is a nested method call. First, nsstring calls the alloc method. This is a relatively underlying method call to obtain memory and initial instantiated objects.
The second piece is a call to init on the new object. the init implementation usually does basic setup, such as creating instance variables. the details of that are unknown to you as a client of the class. the second method calls the init method of the new instance object. The init method usually implements some basic startup actions, such as creating instance variables. The details of the init method are transparent to callers.
In some cases, you may use a different version of init which takes input: in some cases, you may use the new init method-with input parameters. Nsnumber * value = [[nsnumber alloc] initwithfloat: 1.0];Original article: learn_objective_c Part 3

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.