"Notes" iOS Development Essentials notes < four >

Source: Internet
Author: User

Reference from http://www.cocoachina.com/ios/20160323/15770.html

1. Generation and resolution of circular references

Generation: Object A and object B reference each other as their own member variables, only to destroy the member variable when the reference count minus 1. the destruction of object a relies on the destruction of object B, while object B destruction also relies on the destruction of object A to form a circular reference, at which point it cannot be freed even if no pointers are accessed by the outside world.

WORKAROUND: ① knows where a circular reference exists, actively disconnects a reference in a reasonable position, is an object collection, and ② uses a weak reference method.

2. The difference between#include and #import,#import and The difference between @class

    • #include and #import have the same effect, which is the behavior defined in the query class ( method);
    • #import不会引起交叉编译, make sure the header file is only imported once;
    • @class indicates that only the name of the class is defined, and the behavior of the specific class is unknown and is generally used for . h files;
    • @class compile more efficiently than #import. The main difference between @class and #import is that it resolves the problem of reference deadlocks and prevents the process from blocking.

3. Key words meaning

@public: The scope of an instance variable of an object can be accessed anywhere ;
@protected: An instance variable scope of an object can be accessed in both the class and subclass ;

@private: The scope of an instance variable can only be accessed in this class (itself ) .

@property

@implementation

4. How to use Performselector to pass in more than 3 parameters, one of which is a struct.

Because the system provides a Performselector API, there are no three parameters available. Therefore, we can only pass an array or dictionary, but the array or dictionary only into the object type, and the struct is not the object type, we can only pass the object into the structure as a property to pass through.

-(ID) Performselector: (SEL) aselector;-(ID) performselector: (SEL) Aselector Withobject: (ID) object;-(ID) Performselector: (SEL) aselector withobject:   (ID) object1 withobject: (ID) object2;

  

The specific implementation is as follows:

typedef struct HYBSTRUCT {int a;int b;} *my_struct; @interface Hybobject:nsobject @property (nonatomic, assign) my_struct Arg3; @property (nonatomic, copy)  NSString *ar G1; @property (nonatomic, copy) NSString *arg2; @end @implementation Hybobject. The memory allocated on the heap, we want to manually release-(void) Dealloc {free (SELF.ARG3);} @end

  

My_struct str = (my_struct) (malloc (sizeof (my_struct))); str->a = 1;str->b = 2; Hybobject *obj = [[Hybobject alloc] init];obj.arg1 = @ "Arg1"; obj.arg2 = @ "Arg2"; obj.arg3 = str; [Self performselector: @selector (call:) withobject:obj];//get correct data at callback-(void) Call: (Hybobject *) obj {NSLog @ "%d%d", Obj.arg3->a, obj.arg3->b);}

5.

"Notes" iOS Development Essentials notes < four >

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.