Questions about a readonly @property in ARC

前端 未结 3 507
死守一世寂寞
死守一世寂寞 2020-12-20 21:10

In my interface (.h) file, I have

@property(readonly) NSString *foo;

and in my implementation (.m) file, I have

@synthesize         


        
3条回答
  •  温柔的废话
    2020-12-20 21:19

    It is here as a declaration to the rest of your code.
    When you a access the property of this class from an other part of your code, you need to know if the object you get is strong or weak.

    It used to be more obvious when ARC didn't exists, because the programmer needed this information. Now, ARC makes a lot of things transparent, so it is true, you might wonder why it is still here.


    Why can’t the compiler intelligently deduce a default setting for a read-only property?

    I assume it would be pretty easy to set the convention that no keyword means strong or means weak. If it hasn't been done, they surely had a reason.

提交回复
热议问题