Questions about a readonly @property in ARC

前端 未结 3 491
死守一世寂寞
死守一世寂寞 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:36

    You've declared a @property that doesn't have a backing ivar. Thus, when the compiler sees @synthesize, it tries to synthesize a backing ivar for you. But you haven't specified what kind of ivar you want. Should it be __strong? __weak? __unsafe_unretained? Originally, the default storage attribute for properties was assign, which is the same as __unsafe_unretained. Under ARC, though, that's almost always the wrong choice. So rather than synthesizing an unsafe ivar, they require you to specify what kind of ivar you want.

提交回复
热议问题