Is it thread-safe to read an instance variable while calling a setter from another thread?

后端 未结 2 974
逝去的感伤
逝去的感伤 2021-01-21 11:29

I have an object with a property:

@interface Car
@property(strong) NSLicensePlate *licensePlate;
@end

I use the property in a method:



        
2条回答
  •  -上瘾入骨i
    2021-01-21 12:13

    When you define properties, you can set them as atomic (the default) or nonatomic.

    Since you're using the atomic default, you should be fine about thread safety, but that also depends on how you implemented frobnicate, setLicensePlate: and cleanLicensePlate.

    Please refer to this question to get more details about atomic vs nonatomic: What's the difference between the atomic and nonatomic attributes?

提交回复
热议问题