working on it ...


Explore Public Snippets

Sort by

Found 748 snippets matching: delegate

    public by WadeCantley  4690260  56  7  0

    iOS - Swift - Add a Done button to a Keyboard Tool Bar

    Adding a done button to the keyboard tool bar and working within the textField delegate to make that happen. In this situation the keyboard is a number pad which doesn't have its own done button.
    //MARK: - Helper Methods
    // This is called to remove the first responder for the text field.
    func resign() {
    // This triggers the textFieldDidEndEditing method that has the textField within it.  
    //  This then triggers the resign() method to remove the keyboard.
    //  We use this in the "done" button action.
    func endEditingNow(){
    //MARK: - Delegate Methods
    // When clicking on the field, use this method.
    func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
        // Create a button bar for the number pad
        let keyboardDoneButtonView = UIToolbar()
        // Setup the buttons to be put in the system.
        let item = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Bordered, target: self, action: Selector("endEditingNow") )
        var toolbarButtons = [item]
        //Put the buttons into the ToolBar and display the tool bar
        keyboardDoneButtonView.setItems(toolbarButtons, animated: false)
        textField.inputAccessoryView = keyboardDoneButtonView
        return true
    // What to do when a user finishes editting
    func textFieldDidEndEditing(textField: UITextField) {
        //nothing fancy here, just trigger the resign() method to close the keyboard.
    // Clicking away from the keyboard will remove the keyboard.
    override func touchesBegan(touches: (NSSet!), withEvent event: (UIEvent!)) {
    // called when 'return' key pressed. return NO to ignore.
    // Requires having the text fields using the view controller as the delegate.
    func textFieldShouldReturn(textField: UITextField!) -> Bool {
        // Sends the keyboard away when pressing the "done" button
        return true

    public by sTiLL-iLL @ SniPitz-KND  183869  1  8  23


    does it work? IDK... havent tried.. the idea is solid... itll prolly work... without to much effort...
    // polyfill first... just in case
    if(!window.CustomEvent) {
      (function(wdw) {
        function CustomEvent ( event, params ) {
          params = params || { bubbles: false, cancelable: false, detail: undefined };
          var evt = document.createEvent( 'CustomEvent' );
          evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
          return evt;
        CustomEvent.prototype = window.Event.prototype;
        wdw.CustomEvent = CustomEvent;
    function ContextConnection_ChannelBroker(document) {
    	var slf = this;
    	this.create = function (evtName, obj) {
    	  var eventChannel = new CustomEvent(eventName, 
    	      bubbles: true,
    	      cancelable: true,
    	      detail: obj
    	  this.fwdResult = function (rslt) {
    			obj.dispatchEvent(evtName, rslt);
    		this.objPxy = (function(fwdResult) {;
    			obj.addEventListener(evtName, function (ev) {
    				return obj.bind(fwdResult(ev));
    			return obj;
    		return objPxy;
    	objPxy.prototype = Object.create(obj.prototype,	{ 
    	  constructor: {
    	    value: objPxy,
    	    enumerable: false
    	objPxy.prototype.on = function (n,fnc) {
    		obj.addEventListener(n, function(e) {
    	objPxy.prototype.emit = function (n,obj) {
    		obj.dispatchEvent(n, obj);
    	return {
    		onSignaled: on,
    		emitSignal:	emit,
    		createContextChannel: create

    public by sTiLL-iLL @ SniPitz-KND  3808  0  8  12

    BakGRoWnd ThREDiNG WrapAH onny

    using System;
    using System.Collections.Generic;
    using System.Threading;
    using System.Threading.Tasks;
    public class BGrounda
    	Thread bgThrd;
    	public int Progress
    	public object Result
    	public bool IsActive
    			if (bgThrd != null)
    				return bgThrd.IsAlive;
    			return false;
    	public delegate void OnWorkDone(ref int progress, ref object rzlt, params object[] args);
    	public event OnWorkDone jobComplete;
    	List<Task> subscribers = new List<Task>();
    	public void RunIT(params object[] arguments)
    			foreach(Task t in subscribers)
    				bgThrd = new Thread(() => {
    					Task.Factory.StartNew(() => {
    						this.DoWork.Invoke(ref prog, ref rzlt, arguments);
    						this.jobComplete(100, ref rzlt, "workComplete");
            public void Subscribe(Task obj)
                return OnWorkHandler;

    public by lbottaro  2960  0  6  0

    C# Delegate method for Windows Form application

    This delegate method can be invoked by a thread (e.g. a background worker thread running into the Window form app) to update the Form GUI asynchronously.
    /// <summary>
    /// ...
    /// </summary>
    /// <param name="text"></param>
    /// <param name="oo"></param>
    private void updateLabel(System.Windows.Forms.Label label, object oo)
       Invoke(new MethodInvoker(
         delegate { label.Text = oo.ToString(); }

    public by cghersi  2694  1  6  4

    Safely Manage Asynchronous Invoke in Winforms

    When dealing with multithreading in WinForms one of the worst issues you encounter are the management of Invoke() method on controls. Instead of spreading the code of blocks if (control.InvokeRequired) { controlInvoke(...); } else { ... } this is a little method that can elegantly solve your issues!
    private delegate object SafeInvokeCallback(Control control, Delegate method, params object[] parameters);
    public static object SafeInvoke(this Control control, Delegate method, params object[] parameters)
        if (control == null)
            throw new ArgumentNullException("control");
        if (control.InvokeRequired)
            log.DebugFormat("Calling with BeginInvoke: {0}", method.Method.Name);
            IAsyncResult result = null;
            try { result = control.BeginInvoke(new SafeInvokeCallback(SafeInvoke), control, method, parameters); }
            catch (InvalidOperationException) { /* This control has not been created or was already (more likely) closed. */ }
            if (result != null)
                return control.EndInvoke(result);
            log.DebugFormat("Calling sync: {0}", method.Method.Name);
            if (!control.IsDisposed)
                return method.DynamicInvoke(parameters);
        return null;

    public by sTiLL-iLL @ SniPitz-KND  2608  1  8  14

    ANonyMUs inLINe WERKuh C#

    ILYNe exeKutin oF wutteva INda BaKGRownD.. SwEET
    //run a worker like an anonymous function
    public class AnonWorker
        private BackgroundWorker bw = new BackgroundWorker();
        private AnonWorker(){   }
        public static AnonWorker Create
            get { return new AnonWorker(); }
        public void Execute(DoWorkEventHandler begin, 
              RunWorkerCompletedEventHandler completed = null,
                     ProgressChangedEventHandler progress = null)
            bw.DoWork += begin;
            (completed != null) ? addComplete() : noop();
            (progress != null) ? addProgress() : noop();
        private void noop()
        {  // nada...  }
        private void addComplete()
          bw.RunWorkerCompleted += completed;
        private void addProgress()
          bw.ProgressChanged += progress;
          // Now.....  run it like this and its gonna be on a separate thread
      AnonWorker.Create.Execute((sender, data) => {
          // work here ....
      (sender, data) => {
          // all done
          // Old Skool.....
      AnonWorker.Create.Execute(delegate {
          // work
      delegate {
          // done

    public by marksimon232  4098  0  6  4

    Swift Collections: Declaring a delegate property

    Delegation works hand in hand with protocols because it allows a class to specify a delegate property which conforms to some protocol.
    In Objective-C, declaring a delegate property involved using the “id” 
    keyword as shown below.
    @interface FirstClass : NSObject
    @property (nonatomic, weak) id<SampleProtocol> delegate;
    In Swift, declaring a delegate property is just like declaring any other 
    property and you specify the protocol name as the type of the property.
    You may notice the question mark syntax which indicates that it’s a property 
    with an optional value (there may or may not be an object assigned to it).
    class FirstClass
        var delegate:SampleProtocol?

    public by marksimon232  2236  0  6  2

    Swift Collections: Calling a delegate method

    In Objective-C, often times, you would see an If statement to check if there 
    was an object assigned to the delegate property before calling the delegate 
    if (self.delegate)
        [self.delegate someMethod];
    In Swift, you can take advantage of the question mark syntax. If the 
    delegate property is empty, nothing after the question mark will be executed.

    public by restlessankur  1716  2  5  0


    how to announce a delegate
    public delegate void hellofunctiondelegate(string message)
    //method is 
    public static void hellofunction(string strmessage)
    /// point delegate to this function
    hellofunctiondelegate d1 = new hellofunctiondelegate(hellofunction);

    public by lbottaro  5437  1  9  4

    How to marshal and unmarshal java class to xml file using JAX-B

    This java code shows how to marshal and unmarshal class data to xml using JAX-B library, contained in javax.xml.bind.JAXB package. MyNetwork object contains two lists, one for Vendor objects and one for Equipment objects. Each Equipment has a list of Cards and each card refers to a specific Vendor. Marshalling and unmarshalling operation is dele
    package com.test.jaxb;
    import javax.xml.bind.JAXB;
    public class MarshallingExamples {
        public MarshallingExamples() {
            MyNetwork network = new MyNetwork();
            Vendor v1 = new Vendor("123", "NameVVV");
            Vendor v2 = new Vendor("567", "NameZZZ");
            Vendor v3 = new Vendor("345", "NameXXX");
            Equipment eqp1 = new Equipment("112233", "TYPE_ABC", "00-14-22-01-23-45");
            eqp1.addCard(new Card(CardType.DWDM, "AABBCC", 2, v1));
            Equipment eqp2 = new Equipment("222333", "TYPE_ZZZ", "00-C4-22-C1-23-C5");
            eqp2.addCard(new Card(CardType.SDH, "AA1234", 1, v2));
            eqp2.addCard(new Card(CardType.ETH, "AACCDD", 4, v1));
            Equipment eqp3 = new Equipment("445566", "TYPE_CDE", "01-C3-2A-C1-AA-C5");
            eqp3.addCard(new Card(CardType.DWDM, "AAFF44", 1, v3));
            eqp3.addCard(new Card(CardType.DWDM, "AABF33", 1, v3));
            eqp3.addCard(new Card(CardType.ETH, "AA33DD", 2, v2));
            JAXB.marshal(network, new File("out.xml"));        
            network = JAXB.unmarshal(new File("out.xml"), MyNetwork.class);
            for(Equipment eqp : network.getEquipments()) {
            for(Vendor vend : network.getVendors()) {
        public static void main(String[] args) {
            new MarshallingExamples();
    • Public Snippets
    • Channels Snippets