I also think there’s no naming pattern corresponding to ns_consumed in your case. Naming patterns are largely driven by NeXTSTEP/Apple and I can’t think of a method in Apple’s frameworks with the same semantics you want.
Note, however, that you can tell Xcode to use a more recent version of Clang Static Analyser that supports the ns_consumed attribute, which was released with checker-254.
I’m using checker-256 (released today, but any version >= 254 should work) and I’ve just tried the following:
// MyClass.h
#ifndef __has_feature // Optional.
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
#endif
#ifndef NS_CONSUMED
#if __has_feature(attribute_ns_consumed)
#define NS_CONSUMED __attribute__((ns_consumed))
#else
#define NS_CONSUMED
#endif
#endif
@interface MyClass : NSObject {
@private
NSString *_string;
}
+ (MyClass *)myClassWithNewStringConsumed:(NSString *) NS_CONSUMED string NS_RETURNS_RETAINED;
+ (MyClass *)myClassWithNewString:(NSString *)string NS_RETURNS_RETAINED;
@end
and
// MyClass.m
#import "MyClass.h"
@implementation MyClass
+ (MyClass *)myClassWithNewStringConsumed:(NSString *)string {
MyClass *o = [MyClass new];
if (o) o->_string = string;
return o;
}
+ (MyClass *)myClassWithNewString:(NSString *)string {
MyClass *o = [MyClass new];
if (o) o->_string = string;
return o;
}
@end
This code gives a static analyser warning for a potential leak of the string stored in s:
// SomewhereElse.m
NSString *s = [[NSString alloc] initWithFormat:@"%d",
[[NSProcessInfo processInfo] processIdentifier]];
MyClass *o = [MyClass myClassWithNewString:s];
[o release];
whereas this code, which uses the method parameter with an ns_consumed attribute, doesn’t give a static analyser warning:
// SomewhereElse.m
NSString *s = [[NSString alloc] initWithFormat:@"%d",
[[NSProcessInfo processInfo] processIdentifier]];
MyClass *o = [MyClass myClassWithNewStringConsumed:s];
[o release];