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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:22:11+00:00 2026-06-09T13:22:11+00:00

I’m more of an Android developer, but i’m beginning to see the light at

  • 0

I’m more of an Android developer, but i’m beginning to see the light at the end of the tunnel on iOS development.

There is, however, one coding pattern I can’t seem to find an equivalent for.

The use of static fields as flags.

Android :

public final static int ERROR_EMPTY = 1;
public final static int ERROR_NO_CONNECTION = 2;
public final static int ERROR_WRONG_USER = 4;

...

if (error == MyClass.ERROR_EMPTY) {//do things}

What would be the proper way to achieve this on iOS ?

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-06-09T13:22:13+00:00Added an answer on June 9, 2026 at 1:22 pm

    Using Objective-C and C

    i often use prefixes:

    typedef enum MyClass_Error {
      // never use MyClass_Error_Undefined
      // or you may favor MyClass_Error_None for a valid error code
      MyClass_Error_Undefined = 0,
      MyClass_Error_Empty = 1,
      MyClass_Error_NoConnection = 2,
      MyClass_Error_WrongUser = 4
      // ...
    } MyClass_Error;
    

    for these value collections. then you get benefits such as typesafety and switch value checking.

    for non-type constants:

    enum { MyClass_ConstantName = 4 };
    

    and feel free to hide these in the *.m when private.

    also note that C enums may have gaps in their defined values (unlike Java’s).

    Update: there’s an even better way to declare an enum, as demonstrated in Abizern’s answer — if you’re sticking with the most recent toolchains. the big reason to use this extension is for binary compatibility and encoding (although i favor fixed-width types for these purposes).


    There are a few other variations, for the cases when you want to use existing types:

    Private Constant

    MyClass.m

    static const NSRange MyClass_InputRange = {1,1};
    

    Public Constant

    MyClass.h

    extern const NSRange MyClass_InputRange;
    

    MyClass.m

    const NSRange MyClass_InputRange = {1,1};
    

    Using C++

    You would likely favor introducing a new scope for these values — either in a class or a namespace, rather than simulating the scope using prefixes.

    Common Mistakes

    • Use of #define for constants (unless definition is mandatory when preprocessing)
    • Use of short identifiers, and identifiers which are not prefixed
    • Use of static values in headers
    • Not using const when possible
    • Declaring them in the header, when they could be in the *.m source.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
In my XML file chapters tag has more chapter tag.i need to display chapters
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.