gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about memory management


From: Maxthon Chan
Subject: Re: Question about memory management
Date: Fri, 07 Jun 2013 17:06:04 +0800

By the way, since you brought it up, in case Info.plist is not viable, can I do 
this: (This is an CGI script in Objective-C and CGIApplication is analogue to 
NSApplication)

// CGIApplication.h (This header is valid in both C and Objective-C.)
#ifndef CGIAPPLICATION_H
#define CGIAPPLICATION_H
#include <CGIKit/CGICommon.h> // I need CGIClass and Foundation include in this.
CGIClass CGIApplication;
CGIApplication *CGIApp;
int __attribute__((noreturn)) CGIApplicationMain(int, char **, const char 
*__restrict, const char *__restrict);
#if defined(__OBJC__)
@protocol CGIApplicationDelegate <NSObject> // …
@interface CGIApplication : NSObject // ...
#endif // __OBJC__
#endif // include guard

// CGICommon.h (This header is dual-mode too. I have a triple-mode boilerplate 
with some convenient inline functions.)
#ifndef CGICOMMON_H
#define CGICOMMON_H
// …
#if defined(__OBJC__)
#import <Foundation/Foundation.h>
#define CGIClass @class
#else // plain old C
#include <objc/runtime.h> // I need struct objc_object
#define CGIClass typedef struct objc_object
// typedef struct objc_object *id; so CGIClass anything will make anything * 
equal to id.
#endif // __OBJC__
// …
#endif // include guard

// main.c (I managed to expose CGIApplicationMain as a C function in an 
Objective-C header, as seen)
#include <CGIKit/CGIKit.h>
// Prototype:
int main(int argc, char **argv)
{
        return CGIApplicationMain(argc, argv, NULL, 
"CGITestApplicationDelegate");
}

在 2013-6-7,下午4:47,David Chisnall <address@hidden> 写道:

> On 7 Jun 2013, at 09:42, Maxthon Chan <address@hidden> wrote:
> 
>> Well can I (just like NSApplication):
>> 
>> 1) In supercalss, define the shared instance as id
>> 2) In superclass, return the shared instance as id or instancetype
>> 3) In superclass, DO NOT set up yet.
>> 4) In superclass, set up in the method asking for the shared instance, which 
>> always use [[self alloc] init]?
> 
> NSApplication is an example of a singleton designed for subclassing.  It 
> provides an explicit mechanism for defining the subclass that should be used 
> for the singleton instance: a string in the Info.plist providing the name of 
> the application class to use.  It also sets up its delegate in this way and 
> gets the name of the nib to load on application start.
> 
> David
> 
> -- Sent from my brain
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]