OC Learning Object as a property of a class

Source: Internet
Author: User

Object as a property of a class

1. A class in target cannot be accessed directly from another 1 target.

2. What does the class attribute represent?

A. The properties of a class represent the common characteristics of such things

B. The properties of a class represent what this class has.

Lights:

Properties: Shape Power price brand remaining life

Method: Illumination.

Audio:

Method: Sound is made.

Door:

Properties: Size Material Color price

Method: Switch

3. What does the class method represent?

A. Represents the behavior of this class. The functionality that this class has.

B. What is the method of a class to analyze the function of this class.

4. The nature of the attribute is a variable.

When the object is created, the attributes in the object are created one after the other by the rules in the class template.

What type of property is in the class template. Then what type of property is in the object.

If the object's property is an object of another 1 classes, this property is just a 1 pointer variable. There is no object to produce.

This is also the time to assign a value of 1 objects to the address to be used normally.

5. Class A can be used as a property of Class B. Represents b possesses a.

The property is only 1 variables. is a 1 pointer variable. The default value is nil and no object is created.

If you want to use it properly. Also assign a value of 1 objects to the A property of the B object.

Exception handling

1. Error:

1). In general, refers to the source code of our program has a syntax error.

2). The consequences of the error: failed to compile, not to mention execution.

2). Solution: Modifying the wrong code to a code that conforms to the syntax specification is not OK.

2. Bugs

1). means that the program can compile, link, and execute. But the result of the program execution is not the preset.

2). Solution: 99% The bug is because the value of the variable does not change as expected.

Debug the breakpoint to monitor how the variable's value changes.

Analysis of why the change is chaotic. So that we can find the bug

3. Exceptions

1). Concept: Refers to the program can compile, link, execute.

When the program is running, the program is in some special circumstances when the execution of the program will be error.

This condition is called an exception.

Features: Exceptions do not necessarily occur. It occurs when the program is in a certain situation when it is running.

2). Consequences: The program immediately terminates the operation. The following code will not execute.

Reasons for the flash-back:

A. The space occupied by the program is too large.

B. An exception occurred in the program

.....

4. Handling of exceptions. '

1). The purpose of handling exceptions: If an exception occurs when the program is executing. The program does not crash, but continues to execute the code down.

2). Use @[email protected] to handle the exception.

3). Use @try to enclose code that is likely to have an exception.

@try

{

The code of the exception may occur at the time of execution;

}

@catch (NSException *ex)

{

}

4). Steps to perform

A. If the code in the @try is executing, an exception occurs. This time the program does not crash.

Instead, it jumps immediately to the execution code in @catch. After the code in the @catch has finished executing, proceed further down.

If the code in @try does not have an exception when it is executed, this time it skips the @catch down execution.

5). Function: Allow the code to execute if an exception occurs without crashing.

5. Use note

1). If an exception occurs when the code in @try executes.

The information for the exception will occur. Encapsulated as 1 NSException objects

Put the address of this object. The parameter assigned to @catch. Then execute the @catch code.

Therefore, the @catch parameter points to the wrong object.

In @catch if you want to get the cause of the exception, you can access this parameter object.

2). The code in the @catch is executed only when an exception occurs.

So [email protected] In general we write the code that handles the exception.

3). @catch can also be followed by 1 @finally blocks of code.

The code in [email protected] will be executed regardless of whether an exception occurred in @try.

4). @[email protected] It's not everything. Not all exceptions can be handled.

C can't handle the exception. Only OC exceptions are handled.

5). @[email protected] is seldom used in our code.

In general, logic judgments are adopted to reduce the occurrence of anomalies.

OC Learning Object as a property of a class

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.