Reputation: 7778
I am integrating some third party code into my app, and at the same time, trying to convert the app to ARC.
I'm attaching a screen shot to show the only two errors. If this is obvious to someone how to recode this section, I would be most grateful.
I have one more pita to solve. What's the most pragmatic way to solve this one:
value = (NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault,
(CFStringRef)value,
CFSTR(" "),
kCFStringEncodingUTF8);
This gives this error:
"Cast of Objective-C pointer type 'NSString *' to C pointer type 'CFStringRef' (aka 'const struct __CFString *') requires a bridged cast"
Thanks again.. I will lose this code asap...
Upvotes: 0
Views: 1359
Reputation: 8337
You shouldn't use -performSelector:
anyway. Use objc_msgSend(target, selector, ...)
instead.
If you call -respondsToSelector:
you can just use [vc setDelegate:self.delegate]
after the if-statement. The same is true for the first line. Replace it with:
UIViewController *vc = [vcClass alloc]; // vc = [[vcClass alloc] initWithSomething:[specifier file] ...]; if the initSelector is known at compile time
If the initSelector is dynamically generated:
objc_msgSend(vc, initSelector, [specifier file], ...);
Hope this helps.
Update: Answer to the second question
If you transfer CF objects to Objective-C objects, ARC needs to know how the memory management is handled. You have to insert __bridge
, __bridge_retained
or __bridge_transfer
before the cast:
NSString *value;
value = (__bridge_transfer NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (__bridge CFStringRef)value, CFSTR(" "), kCFStringEncodingUTF8);
You use __bridge
if you only want to cast between CF and Objective-C, __bridge_retained
if it's a retained value and you handle that later using CFRelease and __bridge_transfer
if you want to transfer the object from CF to Objective-C or vice-versa.
Upvotes: 2
Reputation: 104698
You should use normal objc messaging, rather than performSelector:
all over the place like that.
As well, you should:
vc
to the result of the initializer.release
(or call [obj performSelector:@selector(release)];
) in an ARC program - the compiler will handle that for you.One final underlying problem is that the initializer should not use a selector like that. If you really need that form, consider using/passing a convenience constructor instead of an initialization selector.
Upvotes: 1
Reputation: 1883
The only reason you'd ever use performSelector: is when the selector is dynamically generated, if you know what selector you are going to use, then you should use it, so performSelector:@selector(alloc) makes absolutely no sense.
Upvotes: 1