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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:02:33+00:00 2026-05-27T08:02:33+00:00

Often times I initialize my model class variables in my AppDelegate so they can

  • 0

Often times I initialize my model class variables in my AppDelegate so they can be used by different ViewControllers without passing their instance across class files. However, every time I import AppDelegate into a .m file to access these variable’s data I feel like I’m doing some wrong.

Is this the the correct way for accessing these variables or should I be doing something differently?

EDIT:
My problem isn’t how to access the variables. I currently use this line of code to get my appDelegate instance:

id appDelegate = [[UIApplication sharedApplication] delegate];

Conceptually, I want to know if this is the accepted way to interact with an application’s model classes. It seems, to me, that an application’s AppDelegate manages the application overall. So it seems counterintuitive to import this class into other classes further down an application’s class chain.

  • 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-27T08:02:34+00:00Added an answer on May 27, 2026 at 8:02 am

    Is this the the correct way for accessing these variables or should I
    be doing something differently?

    You’ll find that different people have different opinions about this. The style that I prefer is to have the app delegate pass the necessary information to the first view controller, and have that view controller pass it on to whatever view controllers it creates, and so on. The main reason for this is that it prevents child view controllers from depending on things that they have no business knowing about.

    If you have some detail editor, for example, you want to be able to pass that editor exactly what it needs to do its work. If you give it that information, the editor is completely flexible — it’ll edit any information that you give it. If the editor knows that it should get its data from some external object, like the app delegate, then it loses some degree of flexibility — it can only get data from the thing that it knows about.

    So, it’s fine to set up your data model in the app delegate. But when it comes to providing access to the model, think: tell, don’t ask. That is, have the app delegate tell the first view controller what model object to use, and have that controller tell the next one, and so on. If you have to ask, you have to know who to ask, and that’s where the dependencies start heading in the wrong direction.

    every time I import AppDelegate into a .m file to access these
    variable’s data I feel like I’m doing some wrong.

    Trust that instinct. Think about why it feels wrong.

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

Sidebar

Related Questions

In our development environment each developer has their own dev server. Often times they
Often times, a class would not have a direct output; it manipulates its dependencies,
When I use static variables in C++, I often end up wanting to initialize
Often times I see something like this: <body> <div class=container> </div> </body> Why not
Often times I have a desire to create variables scoped to an if statement.
Often times I need a collection of non-sequential objects with numeric identifiers. I like
Often times a developer on my team will create a new Visual Studio project
Have a n-tire web application and search often times out after 30 secs. How
When writing a T-SQL script that I plan on re-running, often times I use
I have been finding myself using the Chain of Responsibility pattern often (3 times

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.