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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:11:41+00:00 2026-05-18T09:11:41+00:00

I am trying to subclass NSArray , but it crashes the app when trying

  • 0

I am trying to subclass NSArray, but it crashes the app when trying to access the count method. I know that NSArray is a class cluster.

  • But what does this mean?
  • Is there a work around to be able to subclass an NSArray?

I know that I can simply subclass NSObject and have my array as an instance variable but I would rather subclass NSArray.

EDIT:
Reason:
I am creating a card game, I have a class Deck which should subclass NSMutableArray to have a couple of extra methods (-shuffle, -removeObjects:, -renew, etc), and I think it will look cleaner to subclass NSArray rather than having a var.

  • 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-18T09:11:41+00:00Added an answer on May 18, 2026 at 9:11 am

    The problem with adding a category on a class like this is that all instances of the class will inherit the additional methods. That’s both unnecessary (since not every array needs to be able to be shuffled, etc.) and dangerous (because you can’t benefit from typechecking to be sure the NSArray you’re currently referring to is really one that was expected to be shuffled).

    An alternative would be to create your own Deck class that has an NSMutableArray as an instance variable. There you can define actions on your deck exactly as you would like, and the fact that you are using an NSMutableArray becomes an implementation detail. This lets you take advantage of typechecking at compile-time and it lets you change the internal implementation of your Deck class without changing its clients. For instance, if you decided for some reason that an NSMutableDictionary would be a better backing store, you can make all those changes within the implementation of your Deck class without changing any of the code that creates and uses the Deck.

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

Sidebar

Related Questions

I'm trying to specialize a template method of non-template class in its subclass: //
I am trying to create a subclass of WebPart that will act as a
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
I'm trying to subclass wx.Process such that I have a customized process launcher that
I'm trying to subclass str , but having some difficulties due to its immutability.
I'm trying to create my own subclass of socket.socket that will be able to
I've been trying to make a dict subclass inheriting from UserDict.DictMixin that supports non-hashable
I'm trying to make a subclass of NSCalendar, but without much luck. I've tried
I'm trying to draw an NSTextFieldCell subclass that looks like the rounded event item
I'm trying to create a UIView subclass (GradientView) that will fill itself with a

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.