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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:04:04+00:00 2026-06-13T15:04:04+00:00

Possible Duplicate: How to wrap a Struct into NSObject Can the new Clang Objective-C

  • 0

Possible Duplicate:
How to wrap a Struct into NSObject
Can the new Clang Objective-C literals be redirected to custom classes?

I have a custom struct:

typedef struct {
    float f1;
    float f2;
} MYCustomStruct;

that I need to add to an NSArray. I’ve already written a category to create NSValues of these structs, which I then add to the NSArray, however I’d like to simplify that even further using boxed expressions, if possible. I’d love to be able to do this:

@[@(instanceOfMYCustomStruct)];

however, I’m confronted with the following error:

Illegal type ‘MYCustomStruct’ used in a boxed expression

Is there a way to use boxed expressions with custom structs?

  • 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-13T15:04:06+00:00Added an answer on June 13, 2026 at 3:04 pm

    I would use a NSValue to box a struct, as it has built-in support for it. Unfortunately, you cannot use objective-c’s cool literals for it, though:

    struct foo myStruct;
    NSValue *val = [NSValue valueWithBytes:&myStruct objCType:@encode(typeof(myStruct))];
    
    // to pull it out...
    struct foo myStruct;
    [val getValue:&myStruct];
    

    While this may be unwieldy & ugly amidst other objc code, you have to ask yourself – why are you using a struct in the first place in Objective-C? There are few speed performances gained over using an object with a few @property(s), the only real reason I could see is if you are integrating with a C library for compatibility with memory layouts, and even then, the structure of an objective-c object’s memory layout is well-defined, so long as the superclass doesn’t change.

    So what is your real purpose in boxing a struct? If we have that, we can help you further.

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

Sidebar

Related Questions

Possible Duplicate: CSS: wrap text around a bottom-right div? Is it possible to have
Possible Duplicate: How can I declare a thousand separator in read.csv? I actually have
Possible Duplicate: Is it a good idea to wrap an #include in a namespace
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Objective C for Windows iPhone development on Windows Is there any way
Possible Duplicate: Python : how to append new elements in a list of list?
Possible Duplicate: CSS: Ways to break list into columns on page? I was looking
Possible Duplicate: Wrap every 3 divs in a div First thing, i know i

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.