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 9075319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:50:12+00:00 2026-06-16T18:50:12+00:00

I’m currently learning Obj-C and more specifically – protocols. I will need to make

  • 0

I’m currently learning Obj-C and more specifically – protocols. I will need to make up a scenario here for my question to make sense.

First example (with a delegate).

  1. I’m a UIView subclass which requests information from it’s controller to be displayed (or rather how the information should be displayed). I declare a protocol and make a delegate reference object (or whatever it’s called):

    @property (nonatomic, weak) id <protocolName> dataSource;
    
  2. My controller conforms to this protocol and implements the required method.

  3. View sends messages to the Controller, and the Controller answers and everything is fine.

This as far as I know is delegation through protocols and I believe I understand it.

But let’s consider another scenario.

  1. I’m a class which is the brain for a simple level-based game. I say when to show the menu or when to start playing a game level. But I need to know when a level is completed.

Which means this class needs to be ready to receive messages from anyone that implements the protocol, for example from another class which is responsible for the current level. Now this is what I don’t understand. How the protocol should look like and where/how to implement it?

Let me know if my question still doesn’t make sense. Thanks!

  • 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-06-16T18:50:13+00:00Added an answer on June 16, 2026 at 6:50 pm

    Delegate is a one-to-on relationship method for sending message between entities.
    If you want to receive the same message from different class, you can use NSNotification that is a one-to-many relationship.

    Look at the NSNotificationCenter class, especially postNotification method (for sending messages) and addObserver method (used when received a notification)

    EDIT :
    Here’s an example code for delegation.

    Let’s take your game level-based example. You have a LevelManager class and FirstLevel class. If you want the LevelManager to be notice when the FirstLevel ended, you have to declare a protocol in your FirstLevel class

    // FirstLevel.h
    @protocol SomeProtocol <NSObject>
    -(void)levelDidEnd;
    @end
    
    @interface FirstLevel : NSObject
    @property (nonatomic, weak) id<SomeProtocol> delegate;
    @end
    

    Then somewhere in your FirstLevel.m, call your protocol method when the level ended

    // FirstLevel.m
    - (void)playGame {
        if ([player isDead]) {
            [delegate levelDidEnd];
        }
    }
    

    The next step is to implement your protocol to your LevelManager :

    // LevelManager.h
    @interface LevelManager : NSObject <SomeProtocol>
    @property (strong, nonatomic) FirstLevel *firstLevel;
    @end
    

    And then, set your firstLevel.delegate and implement your protocol method

    // LevelManager.h
    - (void)viewDidLoad {
        firstLevel.delegate = self;
    }
    
    - (void) didLevelEnd {
        // do actions here like showing the menu
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Specifically, suppose I start with the string string =hello \'i am \' me And
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.