Questions tagged [delegates]

Delegates can refer to several concepts. An object can rely on another (a delegate) to perform a function. Delegation can also refer to programming language feature making use of the method lookup rules for dispatching self-calls. In C#, a delegate defines which method to call when an event is triggered.

In object-oriented programming, there are three related notions of delegation.

Most commonly, delegation refers to a programming language feature making use of the method lookup rules for dispatching so-called self-calls. Delegation as a language feature supports the prototype-based programming model.

Delegation can also refer to one object relying upon another to provide a specified set of functionalities. In research, this is often referred to as consultation or as aggregation in modeling.

In C#, a delegate is a way of telling which method to call when an event is triggered, keeping the method type.

A Delegate is a type that safely encapsulates a method, similar to a function pointer in C and C++. Unlike C function pointers, delegates are object-oriented, type safe, and secure.

Official Source

11320 questions
4
votes
3 answers

Swift: Call Function in PageViewController from other Viewcontroller

I got an PageViewController which loads two "child "ViewControllers in order to let the user "swipe" through them. I don't want this swipe gesture , but instead I want to have a function inside my ViewController which allows me to use…
Phil Legat
  • 43
  • 1
  • 3
4
votes
1 answer

Animation Delegate not converting to Swift 3.0

I want to implement CABasicAnimation and have the UIViewController notified when the animation is completed. From this resource: http://www.informit.com/articles/article.aspx?p=1168314&seqNum=2 I understood that I can specify the viewcontroller as a…
user594883
  • 1,329
  • 2
  • 17
  • 36
4
votes
1 answer

Swift Protocol in Framework

so i have this weird problem that's been bugging me for the last few hours. I have a framework in which I created a protocol named ChatDelegate (code bellow) public protocol ChatDelegate: class { func chat(_ chatCollectionView: …
Klemen Košir
  • 77
  • 1
  • 7
4
votes
2 answers

Create a delegate with arbitrary parameters

I have a System.Reflection.MethodInfo and would like to have a method that creates a delegate(preferably a Func<...> or an Action<...>) that represents that method, given an instance to invoke it on. So ideally I would like something like the…
JBSnorro
  • 6,048
  • 3
  • 41
  • 62
4
votes
2 answers

How do you set the delegate for an SFSpeechRecognitionTask?

In most cases, setting a delegate is as simple as implementing the delegate protocol in a class and declaring an instance of that class as the delegate for an instance of whatever you're using. I actually used this same basic concept for the…
Bebhead
  • 209
  • 3
  • 14
4
votes
4 answers

How can I make a delegate refer to a specific version of a method?

I'd like to make a delegate that invokes a specific instance method, unfortunately, it seems that if the method is virtual, the override of the method for the inheriting class will be invoked rather than the base version. public class Base{ …
Michael B
  • 7,512
  • 3
  • 31
  • 57
4
votes
2 answers

What's the deal with [[UIApplication sharedApplication] delegate]?

I am using [[UIApplication sharedApplication] delegate] to share a variable across several classes. I set the value in the AppDelegate. I am able to NSLog it from the myAppDelegate.m and see the value. Then I try to NSLog the value when one of my…
Chris
  • 5,485
  • 15
  • 68
  • 130
4
votes
3 answers

C++ event system design

I need to use an event system in C++. I have mainly four requirements : Speed Ease of use Type Safety Friendly Destruction By "Friendly Destruction" I mean the event and the subscriber need to manage their disconnection when one of them get…
noon
  • 335
  • 1
  • 3
  • 11
4
votes
1 answer

Task.Run vs Invoke() difference

I need to pass an argument of type Task to some function that is not presented here. Inside the function this task will be executed in async way. If there a difference between these three ways to pass it: 1. Task.Run((Func)(async () => Foo =…
AsValeO
  • 2,859
  • 3
  • 27
  • 64
4
votes
1 answer

Why can't an Action delegate be used as a WaitCallback for Threadpool?
The delegates WaitCallback and Action share the same signature. Still, as the code below proves, they cannot be regarded as the same type. static void Main(string[] args) { WaitCallback wcb = (o) => Console.WriteLine("Hello from wcb…
HenkGijsbert
  • 481
  • 3
  • 11
4
votes
1 answer

iPhone: How to Close MFMailComposeViewController?

I'm having difficulties closing an email message that I have raised. The email opens nicely, but once it is opened it will not close as the mailComposeController:mailer didFinishWithResult:result error:error handler never gets invoked. As far as I…
iphaaw
  • 6,764
  • 11
  • 58
  • 83
4
votes
2 answers

Why I get error "Cannot synthesize weak property in file using manual reference counting" when defining delegate?

I have protocol and class header in one file: @protocol SomethingDelegate - (void) doSomething; @end @interface SomethingClass @property (nonatomic, weak) id delegate; @end On the .m file: @implementation SomethingClass // in…
Chen Li Yong
  • 5,459
  • 8
  • 58
  • 124
4
votes
5 answers

Build a static delegate from non-static method

I need to create a delegate to a non-static method of a class. The complications is that at the time of creation I don't have an intance to the class, only its class definition. At call time I do have the instance at hand. Thus I need a way…
David Reis
  • 12,701
  • 7
  • 36
  • 42
4
votes
2 answers

Using BeginInvoke/EndInvoke in a multithreaded fashion. How do AsyncCallback, AsyncWaitHandle and IsCompleted interact?

Andreas Huber's answer to this question gave me an idea to implement Concurrent with async delegates instead of the ThreadPool. However, I am finding it harder to understand what's going on when an AsyncCallback is passed to BeginInvoke,…
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
4
votes
1 answer

Delegate method called twice in Xcode 8.1/Swift 3.0 with debugger breakpoint

I have a problem with xcode 8.1/swift 3. I think it might be a bug in the debugger XCode software but thought I would see if anybody sees something I am missing. I am working on an ios application where I need to override the backspace method used…
siege097
  • 83
  • 7