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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:35:27+00:00 2026-05-30T11:35:27+00:00

I have the definition: @interface MyClass: NSObject { NSString *str; id delegate; } -(id)initWithStr:(NSString

  • 0

I have the definition:

@interface MyClass: NSObject
{
   NSString *str;
   id delegate;
}
-(id)initWithStr:(NSString *)str
        delegate:(id)delegate;
@end

and when i send message to my object in the main.m like this:

int main(int argc, const char * argv[])
{
    @autoreleasepool {
       [[MyClass alloc] initWithStr:@"abc-xyz"
                           delegate:self];
    }
}

There is the error “Use of undeclared identifier ‘self’ “. I m a newb of objective-c and I know that the ‘self’ indicates the receiver of the message, but i don’t know how to use it in the main() function. Can anybody tell me what’s wrong about it and how to fix it?

  • 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-30T11:35:29+00:00Added an answer on May 30, 2026 at 11:35 am

    What happens is that self points to the executing object. main function is not in a class, so, YOU CAN`T call self on a function, only on a method of a class. What are you really trying to do? Use the AppDelegate. When you create a new project, Xcode already gives you some files. One of then is called (YOUR_PROJECT)AppDelegate. This is the starting point of your application.

    If you have any customizations to do in the initialization of your app, find your AppDelegate.m file, look for - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method, and place your code inside this method.

    Never mess up with main.m file.

    EDIT:

    For Mac OS X here’s what you should do:

    Create a class to act as a delegate and add that class to the delegate.

     MyDelegate * d;
     MyClass * c;
    
    int main(int argc, const char * argv[])
    {
        @autoreleasepool {
    
           d = [[MyDelegate alloc] init];
    
           c = [[MyClass alloc] initWithStr:@"abc-xyz"
                               delegate:d];
        }
    }
    

    Then, on MyDelegate, implement the callbacks of the protocol.

    If you want to have a callback on main, you will have to use a function pointer. You’ll have to enter in the world of plain C. I don’t recommend since you want to use object oriented stuff. Don’t mix both, or you’ll create a monster.

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

Sidebar

Related Questions

I have the following definition: public interface MessageResponseHandler<T extends MessageBody> { public void responsed(Message<T>
If I have a class which has an interface definition like below; public class
I have an interface definition like this: @interface MasterPanelsController : UIViewController { PanelSuperclass *panels[3];
Lets say you have interface definition. That interface can be Operation . Then you
I have a BOOL value inside my @interface definition in my .h file. Here
I have a COM interface with a following method definition (IDL notation): SCODE GetText( [in,
I know that an interface does not have a body, just a method definition.
Suppose I have a few definitions like so: public interface ICategory { int ID
I have a definition like this def bar(self, foo=None, bar=None, baz=None): pass I want
Consider the following code: // MyClass.h @interface MyClass @property NSInteger Value; @end //MyClass.m @implementation

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.