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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:09:28+00:00 2026-05-29T06:09:28+00:00

I would like to create my own custom NSMutableArray of my custom objects: @interface

  • 0

I would like to create my own custom NSMutableArray of my custom objects:

    @interface Course : NSObject {
        NSString *className;
        NSString *classGrade;
        NSInteger creditHours;
    }

This class will store an array of courses :

    @interface AllCourses : NSObject : NSMutableArray{
        NSMutableArray *arrClasses;
    }

I would like “AllCourses” to inherit from NSMutableArray so i can use it like any other NSMutableArray Object and add\remove courses from it and load it into a tableView etc…
So my question is ,if u would be so kind, is what my implementation of “AllCourses” should look like ?

  • 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-29T06:09:29+00:00Added an answer on May 29, 2026 at 6:09 am

    First of all. If you want to extend a class you need to do this:

    @interface YourCustomClass : SuperClass
    

    In this manner YourCustomClass inherits properties and/or methods of your SuperClass.

    About your question, Apple doc says in NSMutableArray Class Reference

    There is typically little reason to subclass NSMutableArray. The class
    does well what it is designed to do—maintain a mutable, ordered
    collection of objects.

    You could find the same suggestion in this stackoverflow topic: should-i-subclass-the-nsmutablearray-class.

    If you want to subclass NSMutableArray anyway, see the first link (NSMutableArray Class Reference). You must override 5 methods (see section Methods to Ovveride).

    In my opinion you could just use NSMutableArray in the traditional way: create an NSMutableArray instance and add objects to it (here a simple example).

    NSMutableArray *myArray = [[NSMutableArray alloc] init]; 
    NSNumber *myNumber = [NSNumber numberWithInt:2];
    [myArray addObject:myNumber];
    

    Hope it helps.

    Edit

    To override a method, in your .m file, you need to insert that method and add some logic within it. For example (it’s only pseudo code here):

    //.h
    
    @interface YourClass: NSMutableArray
    
    @end
    
    //.m
    
    @implementation YourClass
    
    - (void)insertObject:(id)anObject atIndex:(NSUInteger)index
    {
       // your logic here
    }
    
    // do the same for other ones
    
    @end 
    

    BUT, again, I suggest you to find a different way to do it because it’s quite difficult (in this case) to extends a NSMutableArray class and obtain a fully functional class like the original one.

    Alternative are:

    1. Use Categories
    2. Use composition (inside your class use a NSMutableArray instance variable)

    Finally, I also suggest you to read the following discussion: why-doesnt-my-nsmutablearray-subclass-work-as-expected. In particular, you have to note that

    In general, you tend to subclass system classes much less often than
    you would in C# or Java.

    as Stephen Darlington said.

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

Sidebar

Related Questions

I have my own custom configuration sections but would like to create a new
I would like to create a subsite that has its own custom Permission Levels.
I would like create my own collection that has all the attributes of python
I would like to create my own data format for an iPhone app. The
I'd like to create a map with an int and my own custom class.
hi i would like to create a custom calendar, this calendar will have custom
I need to create a mapping from objects of my own custom class (derived
I'd like to create my own custom HTTP requests. The WebClient class is very
I would like to create a custom CMS within Codeigniter, and I need a
Does such function exist? I created my own but would like to use an

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.