OBJECT-C Basic Learning based on <ios software Development Secrets >

Source: Internet
Author: User

One OC basic data type

1,id type pointer to Object-c object

You can point to any object type, and you can pass any message to Id,id, which returns a run-time exception when the message is not supported, "unrecognized selector send to instance XXX" message;

Commonly used to represent a delegate property of a class, for example: @property id< protocol name > delegate;

2,sel type, the keyword used to define the method

The OC object can accept any message, but not necessarily the response, by means of the method: Respondstoselector () to determine whether the object can respond to a message, protect the code,

-(BOOL) Respondstoselector: (SEL) aselector;->nsobject class

3,nil,null,nsnull--Null value

Nil is used to assign values to objects, NULL to assign values to any pointers, and nsnull for collection operations

A Nil object can accept a message and return a value of 0 without causing an exception

4. Basic data

Integer type int 4 byte, short 2byte, long 32-bit machine 4byte 64-bit machine 8 bits, long long 8 bytes,

Float single-precision float 4-byte, double-precision doubles 8-byte

float a=6.7;

NSLog (@ "%f", a); --->6.700000

NSLog (@ "%.6f", a);----> 6.700000

NSLog (@ "%.10f", a);-----> 6.6999998093

Boolean type bool 1 bytes

BOOL 4 bytes

Character type Char

Enum type

Two-macro definition

#define Define functions, numbers, strings

Static variable, i=0;//, local static variable acting in the method body, equivalent to a global variable

#pragma mark-Used to separate blocks of code

#pragma Mark NETWORK API

Three-memory management

Principles of memory management: who creates who releases

1. Manual memory Management MRR manual retain release

2. Auto Reference count arc Automatic Reference counting

Common memory errors: 1. Memory leaks, objects are not released at the end of use, causing the phenomenon of resident memory; 2. Over-release, the object has not been used to be released, early release caused the system to crash.

Operations that can increase the reference count:

1.alloc new retain copy makes the reference count of the object +1;//requires the programmer to release it manually

2. Using the class method to create the object, the reference count +1, created internally by the system method, released by the system itself

3. When the parent control loads the child control, [self addsubview:xxx] makes the reference count of the object +1

4. When assigning a value to a property, the object's reference count is +1;

5. Add an object to the array, reference count +1, delete the object reference count in the array-1;

Ways to reduce the number of reference counts:

Release Autorelease the reference count of the object-1;

When the reference count is 0 o'clock, the Dealloc method of the object class is called automatically, and the memory occupied by the object is retracted

Global objects are freed in the Dealloc method of this class

When a static method creates an object that is declared global, the object is automatically freed by the system, and the reference count is kept once, otherwise it crashes when the object is reused in another method

Objects created within the method body can be added to the auto-release pool using Autorelease and released after a certain period of time

OBJECT-C Basic Learning based on <ios software Development Secrets >

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.