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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:45:40+00:00 2026-05-27T01:45:40+00:00

I’ve attempted to compile, but every time I do, one method throws a strange

  • 0

I’ve attempted to compile, but every time I do, one method throws a strange “expected a type” error. I have a method in the header:

-(ANObject *)generateSomethingForSomethingElse:(NSString *)somethingElse;

The error points at the return type for this method. I’ve imported ANObject into the header using #import "ANObject.h" and ANObject is compiling fine..

Why is this happening?

  • 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-27T01:45:40+00:00Added an answer on May 27, 2026 at 1:45 am

    This is to do with the order that the source files are compiled in. You are already probably aware that you can’t call a method before it is defined (see below pseudocode):

    var value = someMethod();
    
    function someMethod()
    {
        ...
    }
    

    This would cause a compile-time error because someMethod() has not yet been defined. The same is true of classes. Classes are compiled one after the other by the compiler.

    So, if you imagine all the classes being put into a giant file before compilation, you might be able to already see the issue. Let’s look at the Ship and BoatYard class:

    @interface BoatYard : NSObject
    @property (nonatomic, retain) Ship* currentShip;
    @end
    
    @interface Ship : NSObject
    @property (nonatomic, retain) NSString* name;
    @property (nonatomic, assign) float weight;
    @end
    

    Once again, because the Ship class has not yet been defined, we can’t refer to it yet. Solving this particular problem is pretty simple; change the compilation order and compile. I’m sure you’re familliar with this screen in XCode:

    But are you aware that you can drag the files up and down in the list? This changes the order that the files will be compiled in. Therefore, just move the Ship class above the BoatYard class, and all is good.

    But, what if you don’t want to do that, or more importantly, what if there is a circular relationship between the two objects? Let’s increase the complexity of that object diagram by adding a reference to the current BoatYard that the Ship is in:

    @interface BoatYard : NSObject
    @property (nonatomic, retain) Ship* currentShip;
    @end
    
    @interface Ship : NSObject
    @property (nonatomic, retain) BoatYard* currentBoatYard;
    @property (nonatomic, retain) NSString* name;
    @property (nonatomic, assign) float weight;
    @end
    

    Oh dear, now we have a problem. These two can’t be compiled side-by-side. We need a way to inform the compiler that the Ship* class really does exist. And this is why the @class keyword is so handy.

    To put it in layman’s terms, you’re saying, “Trust me man, Ship really does exist, and you’ll see it really soon”. To put it all together:

    @class Ship;
    
    @interface BoatYard : NSObject
    @property (nonatomic, retain) Ship* currentShip;
    @end
    
    @interface Ship : NSObject
    @property (nonatomic, retain) BoatYard* currentBoatYard;
    @property (nonatomic, retain) NSString* name;
    @property (nonatomic, assign) float weight;
    @end
    

    Now the compiler knows as it compiles BoatYard, that a Ship class definition will soon appear. Of course, if it doesn’t, the compilation will still succeed.

    All the @class keyword does however is inform the compiler that the class will soon come along. It is not a replacement for #import. You still must import the header file, or you will not have access to any of the class internals:

    @class Ship
    
    -(void) example
    {
        Ship* newShip = [[Ship alloc] init];
    }
    

    This cannot work, and will fail with an error message saying that Ship is a forward declaration. Once you #import "Ship.h", then you will be able to create the instance of the object.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.