Delegates vs. events in Cocoa Touch

后端 未结 3 1973
孤城傲影
孤城傲影 2021-01-19 01:21

I\'m writing my first iPhone app, and I\'ve been exploring the design patterns in Cocoa Touch and Objective-C. I come from a background of client-side web development, so I

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-19 01:55

    One clear distinction is that delegate methods can have return values since there is a one-to-one relationship. On the other hand events are loosely coupled to the sending class, which usually doesn't care if anything responds or not.

    Other delegate methods are simply there for convenience and can have corresponding events that are also triggered.

提交回复
热议问题