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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:16:19+00:00 2026-06-02T21:16:19+00:00

I have to cast an object to a type which is contained in a

  • 0

I have to cast an object to a type which is contained in a string and I don’t know if it’s possible.

My class is in a string :

NSString *myClass = @"User";

and I have an object that I want to cast with this type.

object = (myClass)object; // Doesn't work
object = (myClass *)object; // Doesn't work

How can I do that ?

  • 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-02T21:16:21+00:00Added an answer on June 2, 2026 at 9:16 pm

    There’s no point to doing this — objects’ static types only get checked at compile time, and this could only happen at runtime even if there were a way to do it (since objects such as strings don’t actually exist until runtime).

    If you’re trying to change the object from one class to another, that wouldn’t work anyway — casting from one pointer type to another only lies to the compiler about what type of data it points to, it doesn’t actually change the data. In order to convert objects from one type to another, there has to be a method or function that takes the data from the old object and creates a new object of the desired type (such as NSString’s dataUsingEncoding: to convert from NSString to NSData).

    But if you have a dynamically selected class and you need some type to give the variables for instances of that class, you can just use id (possibly with a protocol if all the possible classes respond to the same messages).

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

Sidebar

Related Questions

In java we have Object type which can be used to cast to specific
I have following exception in the foreach loop Unable to cast object of type
I have a class Something that implements ISomething . How can I convert/cast from
I have this method to Serialize an object with any type public static string
Using reflection I have an object which I need to cast into an iterable
I have an object which contains an array of any type (not a priory
I have a property of type object , which contains an Enum value, and
I have a class which uses an ISet as a collection type as below:
I would like to have an explicit cast between from a string to an
Well, I have a class Customer (no base class). I need to cast from

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.