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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:37:46+00:00 2026-05-25T21:37:46+00:00

I am trying to compare the classes of an id object. However, if I

  • 0

I am trying to compare the classes of an id object. However, if I try and compare the object’s class to the class of NSNumber, it won’t register as equal to, even though I have set some variables to NSNumbers. Please can you tell me why it isn’t registering, here is my code.

NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject:n.title forKey:@"title"];
[dict setObject:[NSNumber numberWithBool:n.allDay] forKey:@"allDay"];
[dict setObject:[NSNumber numberWithInt:n.availability] forKey:@"availability"];
[dict setObject:[NSNumber numberWithInt:n.createdBy] forKey:@"createdBy"];
[dict setObject:n.endDate forKey:@"endDate"];
[dict setObject:n.location forKey:@"location"];
[dict setObject:n.notes forKey:@"notes"];
[dict setObject:n.ownerUsername forKey:@"ownerUsername"];
[dict setObject:n.startDate forKey:@"startDate"];
[dict setObject:[NSNumber numberWithInt:n.status] forKey:@"status"];
NSMutableString *json = [NSMutableString string];
[json appendString:@"{"];
for (NSString *key in [dict allKeys]) {
    id obj = [dict objectForKey:key];
    if ([[dict allKeys] indexOfObject:key] == 0) {
        if ([obj class] == [NSNumber class]) 
            [json appendFormat:@"\"%@\":%@", key, obj];
        else
            [json appendFormat:@"\"%@\":\"%@\"", key, obj];
    }
    else {
        if ([obj class] == [NSNumber class]) 
            [json appendFormat:@",\"%@\":%@", key, obj];
        else
            [json appendFormat:@",\"%@\":\"%@\"", key, obj];
    }
}
[json appendString:@"}"];
  • 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-25T21:37:46+00:00Added an answer on May 25, 2026 at 9:37 pm

    Use: if ([obj isKindOfClass:[NSNumber class]]) …

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

Sidebar

Related Questions

I have the following classes and I am trying to call Compare method from
When trying to compare software versions 5.12 to 5.8, version 5.12 is newer, however
I am trying to compare two tools execution time, which I have installed in
Trying to compare voids for a sorting algorithm. I have this so far but
I have a List(Of AddlInfo) with AddlInfo being an object. I'm trying to pass
I have the following simplified classes: public class BaseContainer { public BaseContainer() { Children
We have several classes in place for our CMS and I'm trying to get
I am trying to compare to a defined constants in C, and I have
I'm trying to write a function in three classes that will compare two lists
I'm trying to create a set of custom objects of the class Point point.h

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.