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!
To store an Objective-C object in an
structyou have a couple of options, the one I see most is to store it in the struct as__unsafe_unretainedand then maintain astrongreference to it elsewhere.From the “Common Issues While Converting a Project” section of the ARC Transition Notes:
They seem to imply
__bridgeis the way to castvoid *toidbut are not 100% clear on this.The other option, which makes more sense to me personally and I’ve seen more often I think:
Hope this helps!