Best way to set a retained property to a newly created object

前端 未结 4 1867
南笙
南笙 2021-01-05 22:21

Which is the best way to handle creating an object to live in a retained property? I\'ve included several examples.

Assume the property is:

@property         


        
4条回答
  •  醉酒成梦
    2021-01-05 22:34

    Option 1 is correct.

    Option 2 is absolutely wrong. You never call -release on the results of a property accessor.

    Option 3 is avoiding properties entirely. This is actually correct in your -init method, but in other methods it's better to use the property setter unless you have a good reason to avoid it.

    Option 4 is correct as well, though it's more verbose than option 1. Your call.

    Edit: I misread your option 4 originally.

提交回复
热议问题