Delegates in objective c

前端 未结 2 1663
有刺的猬
有刺的猬 2020-12-19 18:17

First I should tell you that ive little knowledge of Objective C or C#.So when one of my collegues asked me whether there is anything like delegates in Objective C,I wondere

2条回答
  •  再見小時候
    2020-12-19 19:00

    C# delegates are something like NSInvocations in Objective-C:

    • each knows the object that will be the target of the call
    • each knows the method that will be called

    however, an NSInvocation goes further:

    • it knows the arguments to pass to the method
    • it can store the return value

    You probably wouldn't use NSInvocation to implement a pattern like C# delegates (which are a form of Proxy pattern). Personally I'd choose to use an object that forwards messages it receives to the target object, using the standard message-forwarding features of the runtime.

提交回复
热议问题