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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:03:12+00:00 2026-05-17T01:03:12+00:00

I have an enum in my objective-C code similar to this: typedef enum {

  • 0

I have an enum in my objective-C code similar to this:

typedef enum {
    FRUIT_APPLE = 1,
    FRUIT_PEAR = 2,
    FRUIT_BANANA = 3,
    // etc. 
} Fruit

I need to be able to return an array of these in a method, something like this:

@implementation FruitTest

static Fruit fruits[] = {FRUIT_APPLE, FRUIT_BANANA};

+(Fruit[]) fruits
{
    return fruits;
} 

@end

However, this generates a compile error:

#1  'fruits' declared as method returning an array 
#2  Incompatible types in return

Any ideas on how to solve this?
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-05-17T01:03:12+00:00Added an answer on May 17, 2026 at 1:03 am
    • With C Code, you cannot return an array directly like your current code but you need to return a pointer. In obj-c, you can also use NSArray, which you can return.

    • However, you cannot make an array of enum, neither an array of int or NSInteger, you need to do like fruits = [NSArray arrayWithObjects:[NSNumber numberWithInt:enumValue]];

    Your code should look like:

    static NSArray *fruits;
    
    + (NSArray *)myFruits {
      if (!fruits) {
        fruits = [NSArray arrayWithObjects:[NSNumber numberWithInt:enumValue], nil];
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Objective-C protocol: typedef enum { ViewStateNone } ViewState; @protocol ViewStateable -
I have the following enum in Objective-C: typedef enum { APIErrorOne = 1, APIErrorTwo,
Possible Duplicate: Convert objective-c typedef to its string equivalent I have an enum declared
I have enum like this [Flags] public enum Key { None = 0, A
I have enum like this: public enum ObectTypes { TypeOne, TypeTwo, TypeThree, ... TypeTwenty
I have an enum in a file: goog.provide('animals.Fish'); animals.Fish = function(obj) { this.name_ =
I have an enum class called Gender , and I have values in this
I have 4 numbers 0-3 which is an enum (objective-c) and I'd like to
In an class header I have seen something like this: enum { kAudioSessionProperty_PreferredHardwareSampleRate =
Have enum with inner fields, kind of map. Now I need to get enum

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.