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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:54:45+00:00 2026-06-06T06:54:45+00:00

I want to use a user inputed name in the form of an NSString

  • 0

I want to use a user inputed name in the form of an NSString to create a new instance of my class. I have seen NSClassFromString but i’m not getting it. My end goal is to have the user enter a name of an expense and then use that entered name, which is stored in an NSString variable, to create a new instance of my class. Then the user will enter a few more things that will set the instance variable of the new object.

This will all be in a loop where the user will be able to create as many new objects as they want and the objects will be stored in an array for latter storage and use. But i’m stuck on how to dynamically create a new instance of my class.

  • 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-06T06:54:47+00:00Added an answer on June 6, 2026 at 6:54 am

    What kind of object are you trying to create? Do you always want to create the same kind of object, or do you want to let the user enter the object type, and create an object of that type?

    If you want to always create the same kind of object and set one of it’s properties to a user-entered string, that’s easy.

    Add a UITextField and button to a view controller. In the action method for the button, get the text value from the text field, and use that to set the text in your object:

    MyObject *anObject = [[MyObject alloc] init];
    anObject.stringProperty = theTextField.text;
    

    If you want the user to be able to input the class name, don’t. That is far too fragile. The user could easily enter a classname for a class that would cause your app to behave unexpectedly, or even crash. You would use NSClassFromString for that, but it is a really bad idea to let the user specify a class name. Don’t do it.

    Instead, have the user pick from a list of different options (using buttons, or a table view, or a stepper, or something else) and then use a switch statement to create a new object of the requested type. You’d have a case for each supported type of object the user could create.

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

Sidebar

Related Questions

I have two User Controls already created now I want to use one as
I have an asp.net user control on which I want to use jquery ajax.
Hi I have a site where I use a User Table. I want to
Hay guys, i want to use something like this users = User.objects.all() but i
I want to use user name and password to login admin panel with cURL
I have some properties defined by the user, and then I want use them
I want to use the user structure in wordpress for a website, but when
So I have an input form that I want to use to update a
I have one user control in wpf. And I want to use this user
I have a RichTextBox on my form, and I want to use the default

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.