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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:22:28+00:00 2026-06-15T08:22:28+00:00

If I have an object myObject of class id, how would I cast it

  • 0

If I have an object myObject of class id, how would I “cast” it as a CGPoint (given that I have performed introspection and know myObject to a CGPoint)? This is despite the fact that CGPoint is not a real Obj-C class.

Simply doing (CGPoint)myObject returns the following error:

Used type 'CGPoint' (aka 'struct CGPoint') where arithmetic or pointer type is required

I want to do this so that I can check if the object being passed to an NSMutableArray is a CGPoint, and if it is, to wrap the CGPoint in an NSValue automatically; e.g.:

- (void)addObjectToNewMutableArray:(id)object
{
    NSMutableArray *myArray = [[NSMutableArray alloc] init];
    id objectToAdd = object;
    if ([object isKindOfClass:[CGPoint class]]) // pseudo-code, doesn't work
    {
        objectToAdd = [NSValue valueWithCGPoint:object];
    }
    [myArray addObject:objectToAdd];
    return myArray;
}

ADDITIONAL CODE

Here are the functions I use to perform “introspection”:

+ (BOOL)validateObject:(id)object
{
    if (object)
    {
        if ([object isKindOfClass:[NSValue class]])
        {
            NSValue *value = (NSValue *)object;
            if (CGPointEqualToPoint([value CGPointValue], [value CGPointValue]))
            {
                return YES;
            }
            else
            {
                NSLog(@"[TEST] Invalid object: object is not CGPoint");
                return NO;
            }
        }
        else
        {
            NSLog(@"[TEST] Invalid object: class not allowed (%@)", [object class]);
            return NO;
        }
    }
    return YES;
}

+ (BOOL)validateArray:(NSArray *)array
{
    for (id object in array)
    {
        if (object)
        {
            if ([object isKindOfClass:[NSValue class]])
            {
                NSValue *value = (NSValue *)object;
                if (!(CGPointEqualToPoint([value CGPointValue], [value CGPointValue])))
                {
                    NSLog(@"[TEST] Invalid object: object is not CGPoint");
                    return NO;
                }
            }
            else
            {
                NSLog(@"[TEST] Invalid object: class not allowed (%@)", [object class]);
                return NO;
            }
        }
    }
    return YES;
}

+ (NSValue *)convertObject:(CGPoint)object
{
    return [NSValue valueWithCGPoint:object];
}
  • 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-15T08:22:29+00:00Added an answer on June 15, 2026 at 8:22 am

    A CGPoint is not an Objective-C object. You cannot pass one to your addObjectToNewMutableArray: method. The compiler will not let you.

    You need to wrap the CGPoint in an NSValue and pass that wrapper to your addObjectToNewMutableArray: method.

    If you have an NSValue and you want to test whether it contains a CGPoint, you can ask it like this:

    if (strcmp([value objCType], @encode(CGPoint)) == 0) {
        CGPoint point = [value CGPointValue];
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object in Javascript that looks like this function MyObject(){ this.name=; this.id=0;
In C#, suppose you have an object (say, myObject ) that is an instance
I have a simple object in the format of class MyObject { public string
I have an object. public class MyObject { .... @Column(name = a_number) @NotNull @NumberFormat(style
I have an object that is generated in one class public class CreatingClass {
I have a class called Object which stores some data. I would like to
I have my templated container class that looks like this: template< class KeyType, class
I have an NSMutableArray, that should be only modified by the owner object (MyObject).
If I have a simple object: class MyObject { public string MyValueProperty { get;
I have been using NSJSONSerialization class for converting fields of my object to JSON.

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.