• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
ARC and static functions, free functions and C++ member functions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ARC and static functions, free functions and C++ member functions


  • Subject: ARC and static functions, free functions and C++ member functions
  • From: Andreas Grosam <email@hidden>
  • Date: Sat, 12 May 2012 12:45:22 +0200

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@hidden)

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:

This email sent to email@hidden


  • Prev by Date: Re: Accelerate framework
  • Next by Date: AwakeFromNib called twice for sheet
  • Previous by thread: Re: Accelerate framework
  • Next by thread: AwakeFromNib called twice for sheet
  • Index(es):
    • Date
    • Thread