Under what conditions is @synthesize automatic in Objective-c?

前端 未结 5 2001
自闭症患者
自闭症患者 2020-12-01 18:04

Under what conditions is @synthesize automatic in Objective-c?

Perhaps when using LLVM 3.0 and up? From reading around the net it seems like

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 18:18

    As of Xcode 4.4, if you don't write @synthesize or @dynamic for a property. the compiler acts as though you had written @synthesize property = _property.

    Prior to Xcode 4.4, you must do one of the following things for each property or else the compiler will issue a warning and you will get a runtime error. In Xcode 4.4 or later, you may do any of the following things instead of letting the compiler automatically synthesize the property accessors and instance variable.

    1. Use the @synthesize directive.
    2. Use the @dynamic directive and somehow provide the property getter and (if necessary) setter at runtime.
    3. Explicitly write the property getter method and, if the property is readwrite, the property setter method.

    Note that you can use the @synthesize directive (or the @dynamic directive) and also explicitly provide the getter and/or setter methods. But @synthesize provides them if you omit them.

提交回复
热议问题