开发者

Passing Data To Delegate

I have a bunch of outlets in a controller object that another controller needs to be passed. If it was only 2 or 3 values, I'd just pass them as parameters to the delegate method (not directly the outlets, but by copying the value to variables)

However, there are quite a few. What is the best way to handle this? I see three approaches:

  • I could create a new ob开发者_如何学编程ject that holds all these properties and pass that.

  • I could just pass the controller in the delegate method [self.delegate didClickDone:self]. The problem with this approach is this: am I allowed to access another controller's outlets from the outside?

  • I could follow the 2nd option but copy every outlet's value to a property and allow the other controller to access them via accessor methods.

What is the best way to approach this?


You are always allowed to do what you allow yourself. However some approaches may prevent Apple from accepting your App for the Appstore. This is not the case here ;)

If there are many values to pass I'd go for

  • An array if the passed objects contained are of the same type/kind
  • Use a data class if the values are heterogeneous in nature. Like in Refactoring by M.Fowler -> Introduce Parameter Object (page 295).

The dirty way would be, as you suggested, to open the Outlets to other instances than the view controller itself. Prevent that nosy behaviour of other classes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜