---
title: "Connecting delegate classes in Objective-C"  
description: "Connecting delegate classes in Objective-C"  
author: "Tarun Kumar"  
published: 2015-08-06  
updated: 2015-08-06  
canonical: https://www.mindstick.com/forum/33399/connecting-delegate-classes-in-objective-c  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Connecting delegate classes in Objective-C

I've got two [controls](https://www.mindstick.com/articles/66/how-to-create-controls-at-run-time-in-csharp-dot-net) in my [Interface](https://www.mindstick.com/articles/12101/interfaces-in-java-extending-interfaces) [Builder](https://www.mindstick.com/articles/12472/mgs-front-end-builder-for-magento-2-best-selling-product-on-magento-marketplace) file, and each of those controls I've created a separate [delegate](https://www.mindstick.com/articles/777/delegate-and-event-in-c-sharp) class for in code (Control1Delegate and Control2Delegate). I created two "[Objects](https://www.mindstick.com/forum/145447/what-are-objects)" in interface builder, made them of that type, and [connected](https://www.mindstick.com/articles/12941/link-building-and-search-engine-rankings-how-are-they-connected) the controls to them as delegates. The delegates work just fine. My [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) is, I need to share information from one delegate to the other delegate, and I'm not sure how.

What is the best way to do this? Combine the two delegates into one class, or somehow access a third class that they can both read? Since I'm not actually initializing the class anywhere in my code, I'm not sure how to get a [reference](https://www.mindstick.com/forum/774/reference-what-does-this-error-mean-in-php) to the actual [instance](https://www.mindstick.com/forum/155658/testing-connection-to-cloud-sql-instance-with-a-mysql-client-from-vm-instance) of it (if there is an actual instance of it), or even access the "main" class that the [project](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects) came with.

## Replies

### Reply by Anonymous User

You can add outlets from either delegate to the other delegate. There are two ways to add an outlet to an object in IB (assuming you're using Xcode/IB version 3.0 or later):

1. If you have not generated the code for your delegate classes yet, select the desired delegate, then open the "Object Identity" tab in the IB inspector. Add a "Class outlet" of type NSObject. You should then be able to set this new outlet to the other delegate. Of course you will have to generate the code for your delegate class and add the generated source files to your Xcode project before you can load the nib.

2. If you've already generated the code for the delegate class (or added an NSObject to your NIB and set its Class to an existing class in your Xcode project), add an instance variable to the delegate class:

IBOutlet id outletToOtherDelegate;

As long as your Xcode project is open (as indicated by the green bubble in the lower-left of your NIB window), IB will automatically detect the new outlet and allow you to assign it to the other delegate object in your NIB.

Cocoa automatically connects these outlets at NIB load time. Once awakeFromNib is called on instances of your delegate objects, you may assume that all the other objects in the NIB have been instantiated and all outlets have been connected. You should not assume an order on calls to awakeFromNib, however.


---

Original Source: https://www.mindstick.com/forum/33399/connecting-delegate-classes-in-objective-c

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
