OC Knowledge Point Counting

Source: Internet
Author: User
Tags define null

What is the difference between 1./#import and/#include? What is the difference between #import <> and #import ""?

他们都属于预处理指令,其功能都是包含头文件,但是#import 避免了头文件重复包含问题,如果在使用#include 的时候,需要加入头文件卫士的预处理指令,#ifndefine   #define    #endif ,如果使用了 #import 就意味着不需要加入头文件卫士即可以实现不重复包含的功能。    #import <> 其功能是包含头文件的时候,首先从系统目录开始查找,主要用法是用于包含系统框架的头文件。    

What is the nature of the object declared by 2.id?

id 是一个指向oc 对象的指针类型,称其为万能指针。通俗的理解:就是可以指任何oc 的对象,当他指向任意的对象的时候,在运行时表现的具体的对象,这一点说明它具有在动态的特点。需要注意的是,在使用id 类型的时候,不要在 id 后加*,因为其本身就是指针类型。

3. What are the basic principles of manual memory management? How do I avoid a memory leak when using @property?

如果使用new copy alloc 方法创建的对象,其引用计时器为1,那么我们就需要负责释放这个对象release。如果使用retain这样的方法,让对象的引用计数器+1,我们就需要调用release方法释放这个对象,必须保证retain 和 release方法成对出现。如果使用了@property,在手动管理内存的时候,如果在@property 声明的时候,用到 retain 和copy 关键字,那么在初始化对象的时候,不要使用点语法,直接使用成员变量的名字,同时需要复写 dealloc 方法,在dealloc 方法里,需要释放该成员变量。如果是ARC 环境,则需要在 dealloc方法里,将成员变量指向nil.

4.iOS platform, appear nil,nil,null,nsnull, in the literal sense, they all mean empty, but what do they really mean? What is the difference between each other?

__darwin_null a constant of 0, cast to void *, which means that an empty address is represented. The meaning of the expression does not point to anything.
#define __DARWIN_NULL ((void *)0)
Null is also essentially ((void *) 0) Its main function, the C-style pointer, which indicates NULL when pointing to null.
#ifndef NULL#define NULL    __DARWIN_NULL#endif  /* !NULL */
Nil is used to denote a case where the value of the Object-c type (Class) is empty
#ifndef Nil# if __has_feature(cxx_nullptr)# define Nil nullptr#  else# define Nil  __DARWIN_NULL# endif#endif
Nil is used to denote when an object pointer in object-c represents a null value.
#ifndef nil# if __has_feature(cxx_nullptr)#   define nil nullptr# else#   define nil __DARWIN_NULL# endif#endif
NSNLL its essence is a class type, which indicates that the semantics are empty objects.
@interface NSNull : NSObject <NSCopying, NSSecureCoding>+ (NSNull *)null;@end
To summarize: Whether it's null, nil, or nil their essence is ((void*) 0), pointing to an empty address is also the usual null pointer. The implication is that the data type of the object can be determined based on the initial value assigned, if NULL, for the C-style pointer type if nil represents the Objective-c class type, if Nil. Represents an object in Objective-c. NSNull An empty object that itself represents a class type.

5. What is the difference between a deep copy and a shallow copy? A shallow copy of its essence, just copy the object pointer, that is, memory or the original memory. Deep copy: Re-applied to the system memory, and the original data are all copied in a deep copy of a copy, shallow copy in the manual management of memory mode, equivalent to the reference counter added 1. Their main difference is that deep copies reallocate memory, and deep copies are the replication we generally understand.

OC Knowledge Point Counting

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.