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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:58:13+00:00 2026-05-11T19:58:13+00:00

I was wondering how I would go about accessing one instance of a class,

  • 0

I was wondering how I would go about accessing one instance of a class, say “ship class” across multiple views.

Lets say I have a rootViewController and three subviews, one Main, one battle, and one landing. Where exactly would I implement an instance of a class that stores all the information on my ship and access it though the other views. If my ship has x missiles left, how does another view access that information to display it. If I implement it on the Main view how does the landing view get that info?

I know there has to be an easy way to do this, and I bet there is a way you are supposed to do it without implementing the ship class in any of the views per se. I am still fairly new to programming for the iPhone though.

Thank you in advance for any help you all may provide.

  • 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-11T19:58:13+00:00Added an answer on May 11, 2026 at 7:58 pm

    Once you have created the single instance of your Ship class, you need to tell any other views what that instance is. So you could make Ship a public property on the class that created it.

    @property (nonatomic, retain) Ship* myShip;
    

    Suppose that class is the app delegate – then, in another file, you’d write something like

    [[[UIApplication sharedApplication] delegate].myShip getNumberOfMasts];
    

    This is simple, and works for a simple project, but it does make the Ship object available to any file in your project – it effectively becomes global data, which can be hard to debug in a larger project. (If something bad is happening to myShip, which object was responsible? If it could be any object in your app, then this is a harder problem to debug than if access is restricted to the two classes that need it.) So, if you want to restrict access to ship, then don’t make myShip a public property – instead have the object that created myShip pass it in initialisation calls when it creates other objects that need access. Something like this

    [[myBattleController alloc] initWithShip:myShip];
    

    If this really is one and only one ship object for the whole application, search on stack overflow for advice on creating singleton objects.

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

Sidebar

Related Questions

Just wondering how people would go about this. Say I have one class that
I'm wondering how I can go about accessing page controls from a separate class
I have a SplitContainer and was wondering how I would go about setting a
I was wondering how one would go about using sqlite3 to validate users in
Just wondering how you would go about implementing something similar to stackoverflow'd related questions.
I'm wondering how you would go about designing a good permgen space string in
I'm wondering how i would go about making the following application: a user signs
I am wondering how I would go about performing a certain function if a
I was wondering how I would go about mapping 2D screen coordinates to a
I'm wondering how I would go about the addition and subtraction of numbers in

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.