iPhone – Use category extension classes with the same method

I want to use the category NSArray Populate.h to extend a class:

@interface NSArray (Populate)
-(NSArray *) populateArray;
@end

If there is another category (from another module or library), use a method with the same name to extend NSArray, how to detect the situation?

For example, if there is NSArray Fill.h:

@interface NSArray (Fill)
-(NSArray *) populateArray;
@end

As far as I know, the runtime engine will silently select one of the versions without any crashes?

You cannot detect this situation, nor can you determine which implementation of -populateArray takes precedence. For this reason, some developers prefer to add the name of their category method before

quoting The Objective-C Programming Language file,

A category cannot reliably override methods declared in another category of the same class.

This issue is of particular significance since many of the Cocoa classes are implemented using categories. A framework-defined method you try to override may itself have been implemented in a category, and so which implementation takes precedence is not defined.

I want to use the category NSArray Populate.h to extend a class: < p>

@interface NSArray (Populate)
-(NSArray *) populateArray;
@end

If there is another Category (from another module or library), use a method with the same name to extend NSArray, how to detect the situation?

For example, if there is NSArray Fill.h:

@interface NSArray (Fill)
-(NSArray *) populateArray;
@end

As far as I know, the runtime engine will silently select one of the versions without any crashes?

You cannot detect this situation, nor can you determine which implementation of -populateArray takes precedence. For this reason, some developers prefer the category method Add the name before

quote The Objective-C Programming Language file,

A category cannot reliably override methods declared in another category of the same class.

This issue is of particular significance since many of the Cocoa classes are implemented using categories. A framework-defined method you try to override may itself have been implemented in a category, and so which implementation takes precedence is not defined.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1062 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.