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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:24:22+00:00 2026-05-15T18:24:22+00:00

I am working on a project with several custom classes. I have a CardModel

  • 0

I am working on a project with several custom classes. I have a CardModel (NSObject) that has some integer properties to hold data, and a Deck (NSObject) that has an array to hold a bunch of CardModels and then a CardView (UIView) that has a CardModel as a property that I make when I select a CardModel from a Deck. And then I’ve got a bunch of UIViewControllers that I move around on a UINavigationController.

My question is about where and when to use the @class compiler directive.

If I subclass a UIViewController by making a new file and subclassing it, should I use the @class MyViewController in the header of MyViewController.h or .m and does it go in the header of the file that actually uses the controller (like when one controller is going to instantiate another controller type and push it to the stack). Or do I need to use it at all? Is it only required if I actually add new properties to my class beyond what’s in the stock implementation? It seems like I’m putting @class all over the place just make sure I don’t get errors but I don’t fundamentally understand when I need it.

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-05-15T18:24:22+00:00Added an answer on May 15, 2026 at 6:24 pm

    You use it in the .h to inform it about a custom class without including the .h for the custom class.

    Example:
    Two custom classes: Car and Wheel

    Car.h
    ----------------
    @interface Car : NSObject {
    }
    - (void)addWheel:(Wheel*)newWheel;
    @end
    

    Car.h doesn’t know about the class ‘Wheel’ so it would throw an error so you could import the Wheel.h like so:

    Car.h
    ----------------
    #import "Wheel.h"
    
    @interface Car : NSObject {
    }
    - (void)addWheel:(Wheel*)newWheel;
    @end
    

    BUT you dont need to do this either. Car.h doesn’t need to know anything about the Wheel class, it just needs to know it exists. So what you use is the @class to just say that “Hey, this class exists. Take my word for it.”

    Car.h
    ----------------
    @class Wheel;
    
    @interface Car : NSObject {
    }
    - (void)addWheel:(Wheel*)newWheel;
    @end
    

    Then inside of the Car.m, when you actually need to know about the Wheel class (properties, methods, etc) you should import the Wheel.h there.

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

Sidebar

Related Questions

I'm working on a web project that will (hopefully) be available in several languages
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I am working a project that does not have a trunk / branches /
I am working on localization for a asp.net application that consists of several projects.
I'm working on several distinct but related projects in different programming languages. Some of
I am working a project where I need to generate a series of classes
Working on a project at the moment and we have to implement soft deletion
I'm currently using some configuration files from several project modules inside batch script(scriptx.sh) which
I am working a hobby project that is a file parsing library written in
I am working on an iPhone project which I have translated to two languages

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.