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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:12:09+00:00 2026-05-26T15:12:09+00:00

I have an issue where I am getting in an object of type id.

  • 0

I have an issue where I am getting in an object of type id. i know its base type is an NSManagedObject but the custom attributes for whatever type it actually is (name, email, etc) are what i really need. in the long run, i am trying to make one method that will turn my custom NSManagedObjects into NSDictionaries. maybe i am going down the wrong path in general but….

If i have something like

-(void)someMethod:(id)obj{
...
Class someClass = NSClassFromString([[obj class] description]);
...

i can get the class from that but then i cannot really figure out how to cast my object as that class.

ideally this would be the next few lines of that code

someClass* myObject = (someClass*)obj;
NSArray *keys = [[[myObject entity] attributesByName] allKeys];
NSDictionary *dict = [myObject dictionaryWithValuesForKeys:keys];
//do something with dict
...

but i cannot figure out how to get an object of the type someClass. I have seen where you can use the NSClassFromString object for an alloc init call like

id someObject = [[className alloc] init];

but that will not work for this situation as i already have an object passed in that I need. any ideas / criticisms? I am really trying to avoid a crap load of if statements for all of my items but it may be the quickest way right now…

  • 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-26T15:12:10+00:00Added an answer on May 26, 2026 at 3:12 pm

    If they are all NSManagedObject subclasses, and all you will be calling on them is valueForKey or other methods that are implemented by NSManagedObject, just cast to NSManagedObject. If I’m missing something, please let me know.

    In answer to your comment on the original question – you already have this in your sample:

    NSDictionary *myObjectDictionary = [[myObject entity] attributesByName];
    

    This gives you a dictionary containing all the attributes of your managed object, with the attribute name as the key in each case. You then use these keys to call valueForKey on your object.

    Perhaps a point I need to make is that it is fine to cast an object as its superclass, if you are not going to call any subclass specific methods on it.

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

Sidebar

Related Questions

I have an issue while getting the file name with out extension from a
I'm having an issue getting a LINQ query to work. I have this XML:
I have an issue in Drupal with getting node content to display itself. I
I have an issue. I am getting data from a MySQL database, and make
A common issue I have is getting confused what $(this) is referring to. I
I'm getting started with Qt and have encountered the following issue: when i compile
Im having issues getting this to work, maybe its not even possible? I have
I have been getting an intermittent issue when executing to_number function in the where
I'm having an issue when passing an object of type Dictionary(Of Int16, Polygon) as
I'm having issues getting the CSS3 box-shadow to look correct. I currently have 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.