computed property versus method

Discussion in 'iOS Programming' started by grandM, Mar 3, 2017.

  1. grandM macrumors 65816


    Oct 14, 2013
    Hi guys

    I was wondering what you guys were doing in your factory? I was about to code a factory to generate an array of Items and saw that many people were using a method to create an Item instance. Seems to me you could just easily use a computed property in your Factory to generate the instance.

    What's the best way to obtain this goal and why?

  2. KALLT macrumors 601

    Sep 23, 2008
    I remember reading (not sure where) that although you can do either, it is a better style to use methods when there is some (expensive) computation involved and properties when there is not (basically just getting a value).

    A good way of thinking about this would be the assumption that you do not know the implementation details of your objects, like you do not know how Apple’s objects work internally. The fact that something is a property or a method can hint at how much computation happens in the background, making you more aware of the performance costs.

Share This Page