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

  • Home
  • SEARCH
  • 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 7619893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:48:16+00:00 2026-05-31T03:48:16+00:00

I have references to ground and air in multiple files. It is usually used

  • 0

I have references to ground and air in multiple files. It is usually used in this context, but not always.

if ([transport.type isEqualToString:@"ground"]) {
  // do something for automobiles
}
else if ([transport.type isEqualToString:@"air"]) {
  // do something else for planes
}
else {
  // we don't care
}

Should I be using string constants to represent ground and air so if I ever change their literal, I just update it in one place? e.g.

NSString * const TransportGround = @"ground";
NSString * const TransportAir = @"air";

I then decide I want to rename ground to be wheels, then I would only update the above string constant.

  • 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-31T03:48:17+00:00Added an answer on May 31, 2026 at 3:48 am

    It sounds like it would be a good idea to define constants like you proposed, most likely in the Transport class.

    While consolidating it into a single location makes long term management easier, it can also help prevent errors that would arise if you happened to misspell one of those separate @"ground" or @"air" instances.

    For example, if in one of the classes where you check the transport type and you accidently misspell @"air" as @"iar", the code would not act as you expect, nor would you have any warning or error generated. By using defined constants, you have the help of the compiler to make sure you spell the defined constants correctly. For example, there’s no way you could spell TransportAir as TransportIar, as the compiler would issue an error when you tried to compile.

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

Sidebar

Related Questions

What i have: Several references to the same partial but with different locals like
I have a problem finding references to this subject and would appreciate some help.
I have a common library where I've put classes that are used between multiple
I am developing this site, it got my CSS file, and also have references
This question is pretty simple, but I'm not seeing why the code isn't working?
C++ references have two properties: They always point to the same object. They can
My doc strings have references to other python classes that I've defined. Every time
I have a solution with several projects. The projects have references to each other
In .Net/C# Application, I have data structures which have references to each other. When
I have two references to a SQLite assembly, one for 32-bit and one for

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.