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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:08:38+00:00 2026-05-24T17:08:38+00:00

I need to attach a method to all my UIViewControllers. The method just returns

  • 0

I need to attach a method to all my UIViewControllers. The method just returns a pointer to my main app delegate class object. However, xcode 4 throws an error “parse issue expected a type” in header file at the declaration of output parameter type MyAppDelegate. If I change it to the other type, for example id, then the error goes away. But I’m using a dot syntax to access main app delegate properties and if I will change the type to id then xcode4 not recognize my main app delegate properties. I have included the definition file of category to those UIViewController class files where I’m accessing this method. Here is definition of my category:

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "MyAppDelegate.h"

@interface UIViewController (MyCategory)

-(MyAppDelegate *) appDelegate; // xcode 4 complains about MyAppDelegate type, though it autocompletes it and show even in green color.

@end

Here is an implementation:

#import "MyCategory.h"

@implementation UIViewController (MyCategory) 

-(MyAppDelegate *)appDelegate{
  MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; 
  return delegate;
}

EDIT: The reason why I’m implementing this category is that I need to have handy shortcut for accessing my main app delegate from any place of the code (in my case from UIViewControler objects):

// handy shortcut :)
self.appDelegate.someMethod;

//not so handy shortcut :(
MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; 
  • 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-24T17:08:39+00:00Added an answer on May 24, 2026 at 5:08 pm

    I think you have a dependency cycle in your header files. If MyAppDelegate.h imports MyCategory.h either directly or indirectly, the first time the category declaration is compiled the compiler won’t know what a MyAppDelegate is. You should remove the import of MyAppDelegate.h from the MyCategory.h header and replace it with a forward class declaration:

    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
    
    @class MyAppDelegate
    
    @interface UIViewController (MyCategory)
    
    -(MyAppDelegate *) appDelegate; 
    
    @end
    

    Then put the import in the .m file instead. This is actually a good general principle. Where possible, use forward class declarations in the headers and put imports in the implementation file.

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

Sidebar

Related Questions

Sometimes to make a variable/method/class name descriptive I need to make it longer. But
I need to attach a file with mailx but at the moment I am
I need to attach some javascript to the onchange event of the Zend_Form_Element. How
I need to attach text labels to objects that are spread randomly across the
Lets say you need to attach some JavaScript functionality to an ASP.NET User Control
When I attach functionality to an element do I need to call .widgetName('destroy') before
Normally to attach a debuger to a running jvm you would need start the
I need to convert some files to PDF and then attach them to an
In fact, my question concerns an algorithm. I need to be able to attach
Need a function that takes a character as a parameter and returns true if

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.