php程序员业余承接网页制作、软件开发。

有需要请联系13714715608

看看案例...

define class for object c

2012-05-24T15:04:26.000000Z yang qing rong

在linux下使用gnustep开发原生object c代码,兼容性很不错!

下面给出代码。

code.m

#import
#import
#import "Site.h"
#import

int main( int argc , char *argv[] )
{
       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    
    NSLog( @"hello world\n" );
    
    NSString *str = @"hello,world";
    NSLog( str );

    NSString *name =[[NSString alloc] init];
    name = @"Yang qingrong";
    NSLog(@"name:%@", name );
    [name release];

    Site *site = [[Site alloc] init];
    [site setDomain:@"wudimei.com"];
    [site setName:@"wudimei cms"];
    [site show];
    [site release];

    Site *site2 = [[Site alloc] init];
    [site2 setDomain:@"cainin.com"];
    [site2 setName:@"cainin job"];
    [site2 show];
    [site2 release];

    [pool drain];
    return 0;
}

Site.h

#import

@interface Site : NSObject
{
   NSString *domain;
   NSString *name;
}


-(void) show;
-(void) setDomain:   (NSString*)domain1;
-(void) setName: (NSString*)name1;

-(NSString*) getDomain;
-(NSString*) getName;

@end

site.m

#import "Site.h"

@implementation Site

- (id)init
{
    self = [super init];
    if (self) {
       
    }
    
    return self;
}

-(void) show{
    NSLog(@"domain: %@  ,name: %@",domain,name);
}


-(void) setDomain: (NSString*)domain1
{
    domain = domain1;
}

-(void) setName: (NSString*)name1
{
    name = name1;
}

-(NSString*) getDomain
{
    return domain;
}

-(NSString*) getName
{
    return name;
}
@end
 

GNUmakefile

include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME=Code   #This is Code
Code_OBJC_FILES=code.m Site.m  #And This is Code too
include $(GNUSTEP_MAKEFILES)/tool.make

compile.sh

sudo chmod a+x /usr/share/GNUstep/Makefiles/GNUstep.sh
. /usr/share/GNUstep/Makefiles/GNUstep.sh
make
echo 'running application...'
obj/Code