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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:07:29+00:00 2026-06-02T13:07:29+00:00

I have some constants coded into a few different viewController and NSObject classes atm.

  • 0

I have some constants coded into a few different viewController and NSObject classes atm. One of the guys at my work said I should put them into a class of their own (i.e. a constants class)

I am wondering what the pro’s and con’s of this type of design would be and also if its something that should be done any clarification on how to do it would be great.

for instance,
do I just create a new NSObject class and have a bunch of #defines in it? then when I need to use them do i just subclass my constants class and use the constants inside this class like I would any other method or variable from another class?

i.e.

myclass.theConstant

any help would be greatly appreicated.

  • 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-06-02T13:07:30+00:00Added an answer on June 2, 2026 at 1:07 pm

    Put constants with the things that use them. Do not create a global “everything constant” file. This makes code reuse a huge headache. For example, if you post a notification, you need a notification name string. So you put that in the class that posts the notification:

    .h
    extern NSString * const MYObjectDidSomethingNotification;
    
    .m
    NSString * const MYObjectDidSomethingNotification = @"MYObjectDidSomethingNotification";
    

    Constants are generally not methods or defines. They’re just constant globals like above. You should avoid #define wherever possible, but there are some places it’s quite useful (like constant UIColor objects, which are frustrating to initialize otherwise).

    Spend a little time in the Apple header files to see examples. Look in UIWindow.h, UITableViewCell.h, and UITableView.h for a couple of good examples of how constants are generally defined.

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

Sidebar

Related Questions

I have a C++ class implementation file which has some constants. The constants appear
I have a class in VB with some constants that represent the string name
I have a bunch of javascript functions which depend on some server-side constants (such
I want to have some constants in a Django Projects. For example, let's say
I have some std::list<char> list_type Now I have to supply contents of the list
In routes.rb, I have: [some routes] match '/me' => scores#all_athlete_scores, :constraints => LoggedInChecker devise_scope
well, i have a big file, there are some contents i needed to be
I'm having some trouble using constraints correctly. I have three tables, 'item', 'store' and
I'm using MySQL 4.1. Some tables have duplicates entries that go against the constraints.
I have an app that, after some clicking, shows activity with news contents. I

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.