I'm trying to convert a project to ARC. The project has a Directed Acyclic Word Graph, which basically means lots of double indirection pointers everywhere.
This is proving quite a challenge to convert to ARC, and one issue in particular has me currently stumped.
Here's the scenario.
Let's say you have an NSString *
:
NSString *b = [[NSString alloc] initWithString:@"hello"];
You also have a double indirection type:
__unsafe_unretained NSString **a;
You want to assign one to the other as follows:
a = &b;
This gives a conversion error:
error: assigning 'NSString *__strong *' to 'NSString *__unsafe_unretained *' changes retain/release properties of pointer
Changing b
to __unsafe_unretained
doesn't work. I've also tried the various bridging casts. Am I missing something obvious here?
Any ideas?
Thanks!
You can use a pointer-to-const-pointer to avoid memory management issues:
you need to use objc_precise_lifetime to make
b
available for the whole context (ARC may releaseb
after last reference)EDIT: This can also be used (but be aware of managing your double pointer)