Ownership of returned quartz objects

I recently asked about auto-implementation of a return quartz object: Auto-advertising for CGMutablePathRef?

Dave DeLong answered my question that there is no auto advertising for quartz (or any NS foundation objects), and I have to use the Create Rule . However, the naming convention in the document reads:

Core Foundation naming conventions, in particular the use of the word "create", apply only to C functions that return Core Foundation objects. The naming conventions for Objective-C methods are determined by Cocoa conventions, whether the method returns a Core Foundation or Cocoa object.

In this account, since my function is a message in a C object, it seems incorrect to call it createSomething. I still want to return this object. What is the best way to approach this? Should I use Get Rule and then for the calling box to explicitly save it? But this is not part of the Cocoa agreement. What is the right way to handle this?

+1
source share
1 answer

Normally, you should return an auto-implemented object from the Objective-C method, which returns a new object. It's easy enough to do this with Core Foundation objects. For example, take this base class method:

+ (CFURLRef)appleWebsiteURL
{
    CFURLRef url = CFURLCreateWithString(NULL,CFSTR("http://apple.com"),NULL);
    return (CFURLRef)[NSMakeCollectable(url) autorelease];
}

, , . iPhone, :

return (CFURLRef)[(NSObject*)url autorelease];
+2

Source: https://habr.com/ru/post/1745120/


All Articles