Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7408427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:54:52+00:00 2026-05-29T05:54:52+00:00

I have: A delegate to handle a socket connection that reads and writes data

  • 0

I have:

  1. A delegate to handle a socket connection that reads and writes data to the socket.

  2. A MyTableViewController with methods to fill a table in a view with data received from the socket.

My question is the following:

What would a valid design approach be to fill the table with data arriving at the socket?
(Given that in the future I will have several other views also using data from the socket.)

I thought I should have a single SocketClient class to handle all messages exchanged through the socket and then notify each relevant UIViewController. But, in this case, when data arrives at the socket, the controller object is already instantiated. Which led me to use the controller as a singleton. It works, but I don’t like this. An alternative would be for all my controllers to be delegates that handle the socket connection. I don’t like this either.

What would your approach be?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:54:53+00:00Added an answer on May 29, 2026 at 5:54 am

    The correct approach here is called Model-View-Controller, and it’s the core architecture throughout Cocoa. The model holds your data (forget the socket for a moment; the tables don’t care where the data comes from). The (table)views display the data, and the (tableview)controllers connect the two.

    So you would have a set of model objects that hold data. They don’t care about how the data is displayed and they don’t care where it comes from (the socket). They just hold the data. Sometimes these are managed by a Singleton, sometimes a pointer to the model is handed to each view controller when the view controllers are created. Either approach is fine. Handing the model to the view controllers is a little more flexible, but takes a little more code.

    Then there is another object, your SocketClient, that fetches data and updates the model. The SocketClient does not hold the data. It just deals with the socket and updating the model. It knows nothing about the view controllers and they know nothing about it.

    Whenever the model changes, the view controllers are notified. This is most often handled via NSNotification, but can also be handled via KVO or delegation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a modal view controller that takes another UIViewController as delegate. My doubt
I have my main application delegate which contains a method that returns an object.
I have create a class MyConnection that extends NSURLConnection. I have implemented some delegate
I have a class that I want to be able the handle the mouse
I have a UIViewController based app and I want to changes data on view
I have a Core Data structure set up. In my application delegate, I have:
I have a class that Handles send & receive over a socket between my
Does the Java language have delegate features, similar to how C# has support for
When i have delegate like public delegate void PrintMe(); (1) PrintMe a = delegate()
I have this delegate in C#. public delegate string ACSharpDelegate(string message); How would I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.