OBJECTIVE-C Study Notes (iii) data members: attributes and instance variables

Source: Internet
Author: User

Type-member Type Member

Members of struct structs are simple, only variables.

There are many members of the class:

Data member Description Object ( The focus of this lecture )

· Instance variable instance variable

· Attribute Property

Functions member function member

· Method

· Initializer Init

· destructor Dealloc

Properties of the class:

By default, the compiler defines PropertyName auto-compositing for properties:

A getter Accessor method: PropertyName

A setter accessor method: Setpropertyname

An instance variable _propertyname

In a read-only scenario, the compiler will only auto-synthesize the property fullname:

A getter Accessor method: FullName

Attribute Description attribute:

Read-write feature ReadWrite (default)/readonly

Multithreading features Atomic (default)/nonatomic

Memory management features:

Strong reference Strong (default)

Weak reference weak prevents memory overflow when circular referencing

copy refers to copy to prevent consequential assignment changes when referencing a type copy.

Others: Retain, assign, unsafe_unretained

Instance variable:

All classes are accessed using attributes, especially if an instance object that accesses the class type property outside of the class, memory error occurs. Most of the classes are also accessed using the self. property. In addition to the following conditions.

• initializer Init

• Dealloc of the destructor

• Custom Accessor methods

Life cycle:

An instance variable of a value type is directly embedded in the heap of an object instance and is disposed of following the release of the object instance memory.

An instance variable of a reference type: The object has a pointer to it itself, and the object's pointer is stored in the instance variable, and arc manages the count for the pointer, releasing the zero-count object.

That is, the object's heap is freed when the pointer to the instance variable and the object's own pointer (in fact the two pointers to the same address are the same), and the heap of the instance variable is released after the pointer to itself fails.

Other: (You may say in the future, first of all)

One:

Protocal: Equivalent to interface in Java;

Interface + implementation is a complete class declaration.

Interface includes declarations of member variables and member methods, inheritance relationships, protocal implementation relationships, and so on.

Implementation is the implementation part

Two:

A variable inside a class declaration is called an instance variable, because it is used internally, so it cannot be accessed externally. Only the properties of the class can be accessed outside the class.

A class variable is a static variable

A variable in a method inside a class is a generic local variable.

Three:

-Represents the instance method, which needs to be instantiated when calling outside the class.

+ represents a class method that does not need to be instantiated when calling outside the class.

OBJECTIVE-C Study Notes (iii) data members: attributes and instance variables

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.