delegates

Why delegate types are derived from MulticastDelegate class why not it directly derive from Delegate class?

醉酒当歌 提交于 2020-01-03 17:25:14
问题 I have a very basic question regarding delegate types. I compared the memebers of Delegate and MulticastDelegate classes in object browser and I couldn't find any new additional member present in MulticastDelegate. I also noticed that the Delegate class has GetInvocationList virtual method. So I assume that the Delegate class should have the capability to hold references to multiple methods. If my assumption is correct I wonder why not custom delegate types directly derive from the Delegate

Why delegate types are derived from MulticastDelegate class why not it directly derive from Delegate class?

[亡魂溺海] 提交于 2020-01-03 17:25:10
问题 I have a very basic question regarding delegate types. I compared the memebers of Delegate and MulticastDelegate classes in object browser and I couldn't find any new additional member present in MulticastDelegate. I also noticed that the Delegate class has GetInvocationList virtual method. So I assume that the Delegate class should have the capability to hold references to multiple methods. If my assumption is correct I wonder why not custom delegate types directly derive from the Delegate

How does D allow delegates as template parameters?

。_饼干妹妹 提交于 2020-01-03 17:17:13
问题 In "The D Programming Language" by Andrei Alexandrescu, there's an example where a delegate is taken as a template parameter: T[] find(alias pred, T)(T[] input) if(is(typeof(pred(input[0])) == bool)) { for(; input.length > 0; input = input[1 .. $]) { if (pred(input[0])) break; } return input; } unittest { int[] a = [1,2,3,4,-5,3,-4]; int z = -2; auto b = find!(delegate(x) { return x < z; })(a); asssert(b == a[4..$]); } Alexandrescu explains that this works because a delegate is actually a fat

Fail in assigning self.delegate it produce unrecognized selector sent

ⅰ亾dé卋堺 提交于 2020-01-03 17:02:55
问题 I'm a new in iOS, and I have trouble in implementing @protocol so sorry if you think this is an easy thing.. i've been searching around stackoverflow.com, the webs and also try uncle Google for a while and I decided to ask here... The main idea is calling a MyViewController from TopViewController and do flip animation I Start with creating the protocols.. // This is my Delegate header // MyViewController.h @protocol MyViewControllerlDelegate - (void) myViewControllerDidFinish; @end @interface

C# - Declaration of types within a namespace

▼魔方 西西 提交于 2020-01-03 16:44:14
问题 what could be a possible use of declaring types within a namespace but not in a class. For ex: namespace Test { public delegate void Ispossible(); } This is valid & does not generate any compilation errors but i can't think of why we would declare it this way as opposed to inside a class. 回答1: A namespace is a high-level unit of organization within .NET. Declaring types within classes is typically frowned upon (but, as with all things, it's not a 100% rule) because it can make the types more

Why do I not need to declare UIAlertViewDelegate in the header?

六月ゝ 毕业季﹏ 提交于 2020-01-03 16:43:09
问题 I thought I had finally managed to understand the concept of a delegate until the following occurred: I changed my header file to remove the reference to the delegate and the Alert still worked. The only difference is that I lose code hinting. //.h #import <UIKit/UIKit.h> //@interface ViewController : UIViewController <UIAlertViewDelegate> @interface ViewController : UIViewController - (IBAction)showMessage:(id)sender; @end //.m #import "ViewController.h" @implementation ViewController -

How to convert a delegate-based callback system into block-based?

廉价感情. 提交于 2020-01-03 11:46:48
问题 I have a class, which has a delegate based system for sending different type of requests. it uses delegate to tell the object when the request is complete and also if it was a success o an error. Now, I also have to check what type of request was it in response to take appropriate action. I have wrapper class that should give me a block based interface for the same. I pass a completion-block and an error-block to a request method which should internally use this delegate based class. And when

How to convert a delegate-based callback system into block-based?

僤鯓⒐⒋嵵緔 提交于 2020-01-03 11:45:02
问题 I have a class, which has a delegate based system for sending different type of requests. it uses delegate to tell the object when the request is complete and also if it was a success o an error. Now, I also have to check what type of request was it in response to take appropriate action. I have wrapper class that should give me a block based interface for the same. I pass a completion-block and an error-block to a request method which should internally use this delegate based class. And when

Why cannot C# resolve the correct overload in this case?

三世轮回 提交于 2020-01-03 06:45:11
问题 I've come across a strange situation which is non-ambiguous, yet the overload resolver doesn't think so. Consider: public static class Program { delegate int IntDel(); delegate string StringDel(); delegate void ParamIntDel(int x); delegate void ParamStringDel(string x); static void Test(IntDel fun) { } static void Test(StringDel fun) { } static void ParamTest(ParamIntDel fun) { } static void ParamTest(ParamStringDel fun) { } static int X() { return 42; } static void PX(int x) { } public

Storing an async function as a variable

♀尐吖头ヾ 提交于 2020-01-03 05:11:45
问题 I have a question that is similar to this question but that differs in that in my case I am dealing with Asynchronous functions. So as the question says I want to store a method in a variable (to call it later) In the case of syncrhonous functions private delegate void eventmethod(); //(for a function without arguments and return void) private eventmethod MySavedEvent; void D() { } MySavedEvent = D; MySavedEvent(); But what happens if the function is actually Task<returnType> D(); How can I