iOS property declaration clarification

前端 未结 5 1709
春和景丽
春和景丽 2020-12-22 18:24

This is a two part question in hopes that I can understand more about the topic.

1) It seems to me that you have two popular optio

5条回答
  •  醉梦人生
    2020-12-22 18:47

    Here are the only property modifiers that Xcode recognizes:

    • nonatomic (does not enforce thread safety on the property, mainly for use when only one thread shall be used throughout a program)
    • atomic (enforces thread safety on the property, mainly for use when multiple threads shall be used throughout a program) (default)
    • retain / strong (automatically retains / releases values on set, makes sure values do not deallocate unexpectedly) (default if ARC and object type)
    • readonly (cannot set property)
    • readwrite (can both set and get property) (default)
    • assign / unsafe_unretained (no memory management shall be done with this property, it is handled manually by the person assigning the value) (default if not ARC or object type)
    • copy (copies the object before setting it, in cases where the value set must not change due to external factors (strings, arrays, etc).
    • weak (automatically zeroes the reference should the object be deallocated, and does not retain the value passed in)
    • getter=method (sets the selector used for getting the value of this property)
    • setter= method (set the selector used for setting the value of this property)

提交回复
热议问题