I would like to define a static function which returns a newly created object,
for example:
static Foo* makeFoo(const char* arg) {
return [[Foo alloc] initWithArg:arg];
}
Do I need to use __attribute__((ns_returns_retained)), or is the above
definition already correct as it is?
Furthermore, are ARC rules fully applied within static functions and free
functions? For example:
Foo* makeFoo(const char* str) __attribute__((ns_returns_retained));
Foo* makeFoo(const char* str) {
NSString* s = [[NSString alloc] initWithCString:str encoding:Encoding];
Foo* result = [[Foo alloc] initWithString:s];
return result;
}
Is local variable 's' released properly?
Furthermore is ARC fully applied within member functions of C++ classes?
For example:
// Objective-C++
#import "Foo.h"
class foo {
public:
foo(const std::string& s = "default") : _s(s) {}
Foo* makeFoo() const {
NSString* s = [[NSString alloc] initWithCString:_s.c_str()
encoding:Encoding];
Foo* result = [[Foo alloc] initWithString:s];
return result;
}
private:
std::string _s;
};
…
#include "foo.h"
@implementation Bar {
foo _foo;
}
- (Foo*) newFoo {
return _foo.makeFoo();
}
@end
If that works, how would I have to declare the C++ member function makeFoo(),
considering two cases:
1) makeFoo is inlined and defined within the class definition
2) makeFoo is defined out of line within a foo.cpp module
Thanks for help!
Regards
Andreas
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]