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

  • Home
  • SEARCH
  • 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 8622021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:57:14+00:00 2026-06-12T06:57:14+00:00

I have an NSString. NSString *str; And I need to store it in a

  • 0

I have an NSString.

NSString *str;

And I need to store it in a struct.

struct {
  int *s;
} st;

And set it.

st.s = str;

So, how should I go about retrieving it?

return (__bridge_retained NSString *)st.s;

I’ve tried the above, and it gives the error: Incompatible types casting ‘int *’ to ‘NSString *’ with a __bridge_retained cast.


Answered the question. Simply define the NSString in the struct like this.

struct {
  __unsafe_unretained NSString *s;
} st;

Thanks, Carl Veazey!

  • 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-12T06:57:15+00:00Added an answer on June 12, 2026 at 6:57 am

    To store an Objective-C object in an struct you have a couple of options, the one I see most is to store it in the struct as __unsafe_unretained and then maintain a strong reference to it elsewhere.

    From the “Common Issues While Converting a Project” section of the ARC Transition Notes:

    If using Objective-C objects is sub-optimal, (maybe you want a dense
    array of these structs) then consider using a void* instead. This
    requires the use of the explicit casts…

    They seem to imply __bridge is the way to cast void * to id but are not 100% clear on this.

    The other option, which makes more sense to me personally and I’ve seen more often I think:

    Mark the object reference as __unsafe_unretained. … You declare the
    structure as: struct x { NSString * __unsafe_unretained S; int X; }

    Hope this helps!

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

Sidebar

Related Questions

i have an error in this code NSString *str = @above string; //load above
I currently have the following code: -(void) inputNumber:(int)number { NSString *str; str = [NSString
Have got an NSString *str = @12345.6789 and want to find out if there
I have a NSString which contains a very large number. I need to convert
i have a string declare as such NSString *str = [[NSString alloc] initWithFormat:@I require
I have the definition: @interface MyClass: NSObject { NSString *str; id delegate; } -(id)initWithStr:(NSString
I have an NSString *str and I want to know if the 2nd character
I have read that to left-pad an NSString all you need to do is
I have an NSString *str = @T%B3%C3%83; where %C3 represents A with an umlut
I have a C function with the following method signature. NSString* md5( NSString *str

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.