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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:42:29+00:00 2026-05-29T08:42:29+00:00

In my code, I’m dynamically creating classes, and trying to store them in a

  • 0

In my code, I’m dynamically creating classes, and trying to store them in a NSMutableDictionary:

NSMutableDictionary* classDict = [ [ NSMutableDictionary alloc ] init ];  

...start loop

Class customClass = objc_allocateClassPair( [ TestClass class ], className, 0 );

[ classDict setObject:customClass forKey:name ]

...end loop

...add methods to certain classes within the dict

...register classes with objective c

When I run the code, a “EXC_BAD_ACCESS” is thrown when it’s trying to add the Class to the dictionary. Is there a way to get around this? That is, is there a way to add a unregistered Class to a NSMutableDictionary? The alternative solution is to use a std:map data structure instead.

Thanks in advance.

  • 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-29T08:42:30+00:00Added an answer on May 29, 2026 at 8:42 am

    To answer the actual question: adding a Class object to a dictionary is simple:

    [dict setObject:[TestClass class] forKey:@"key"];
    

    And I do so often, without any issue. However, you seem to want to add an unfinished class object. The documentation states:

    When you are done building the class, call objc_registerClassPair. The
    new class is now ready for use.

    So maybe your Class object is not “ready for use” yet?

    update after some tests:

    you need to call objc_registerClassPair in order to use Class as an actual object. Calling retain before this time will lead to an EXC_BAD_ACCESS.

    If you want to create classes in a loop, and register them in a later stage, just box the pointers, using:

    [classDict setObject:[NSValue valueWithPointer:customClass] forKey:name];
    

    simply unbox them using Class customClass = [value pointerValue];. After registering you can of course use the Class objects as usual.

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

Sidebar

Related Questions

Code: class Session extends Backbone.Model initialize: -> @bind 'change', @save console.log 'init' class SessionList
Code bellow will create eventstore for named connection. var es = Wireup.Init() .UsingSqlPersistence(DB) .Build();
Code: public class SMH extends Activity { public void onCreate(Bundle b) { super.onCreate(b); setContentView(R.layout.main);
Code goes first: class A { public: ... int *foo() const { return _px;
Code: %define x 0x03 x equ 0x03 What's the difference between them?
Code: public interface IFoo { void Bar(); } public class FooClass : IFoo {
code: #include<iostream> using namespace std; template<class T, int N> class point { T coordinate[N];
code structure @protocal A_Delegate { -(void)doIt:(BOOL)isDone; } Super Class A // has properties of
CODE:1 class Ajay { private void display() { System.out.println(Ajay); } public static void main(String
code is here I am trying to make the Parent element visible when 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.