Naming conventions for BOOL Obj-C 2 properties?

前端 未结 5 1405

I have a readonly BOOL property. What is dominant naming pattern here?

Background: for plain old method declarations, the accepted pattern

- (BOOL)is         


        
5条回答
  •  [愿得一人]
    2020-12-14 18:06

    The convention is definitely to do is... for BOOL getters. The reason you see the property set like that in CalStore is most likely because it's read-only and written that way for basic readability of the header file, since:

    @property(readonly) isEditable;
    

    is generally easier to read than:

    @property(readonly, getter=isEditable) editable;
    

    For the first type of property, in your implementation you could do either of:

    @synthesize isEditable = editable;
    

    or simply define the accessor:

    - (BOOL)isEditable(void) { return editable; }
    

    This leaves the interface file (the header) more easily readable by a potential user.

提交回复
热议问题