Possible solutions:
Rename your method according to the naming conventions of the Objective-C Basic Memory Management Rules, e.g. start the method name with "copy":
- (CFStringRef)copyUTITypeForPath:(NSString *)path {
NSString *extension = [path pathExtension];
CFStringRef result = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)extension, NULL);
return result;
}
Then the caller of the method is responsible for releasing the CFStringRef
eventually.
Or change your method to return NSString *
instead of CFStringRef
:
- (NSString *)UTITypeForPath:(NSString *)path {
NSString *extension = [path pathExtension];
CFStringRef result = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)extension, NULL);
return CFBridgingRelease(result);
}
In this case ARC will take care of releasing the NSString
object.