iOS — “add” methods appearing for autosynthesized properties in codeSense

不羁的心 提交于 2019-12-05 19:48:11

问题


I just created an iOS class with the following properties:

@property (nonatomic, strong) NSString* foo;
@property (nonatomic, strong) NSObject* bar;
@property (nonatomic) CGRect fubar;

I did not put in any @synthesize or explicit ivars for these properties. I then went into the implementation file and started to create a method as follows:

-(void) add

I left the cursor at the end of the word "add". The following method names then popped up in code sense:

addBar: (NSSet*) objects
addBarObject: (objectType *) object
addFoo: (NSSet*) objects
addFooObject: (objectType *) object
addFubar: (NSSet*) objects
addFubarObject: (objectType *) object

What are these methods? Are there any docs for them?


回答1:


That are accessor methods that a class can implement to support Key-Value Coding for mutable to-many relationships, see Mutable Unordered Accessors in the "Key-Value Coding Programming Guide":

In order to be key-value coding complaint for a mutable unordered to-many relationship you must implement the following methods:

-add<Key>Object: or -add<Key>:. At least one of these methods must be implemented. These are analogous to the NSMutableSet method addObject:.

The same "strange" autocompletion happens for other Key-Value coding accessor methods, for example:

- (void)remove...
- (void)intersect...
- (NSUInteger)countOf...


来源:https://stackoverflow.com/questions/15327444/ios-add-methods-appearing-for-autosynthesized-properties-in-codesense

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!