杨庆荣的博客

工作之余接单:公司产品展示网站建设、电商网站建设、小程序、app开发。+86 13714715608

gnustep写一个类

点击 2107    创建时间 2012-10-30 22:34:25

People.h

 #import <Foundation/Foundation.h>   
 @interface People : NSObject  
 {  
    NSInteger age;  
    NSString *name;  
 }  
 -(NSString*)getName;  
 -(void)setName:(NSString*)name2;  
 -(void)setAge:(NSInteger)age2;  
 -(NSInteger)getAge;  
 @end

People.m

 #import "People.h"  
 @implementation People  

 - (NSString*) getName  
  {  
      return name;  
  }  

  - (void) setName:(NSString*) name2  
  {  
      name=name2;  
  }  
  -(void)setAge:(NSInteger)age2  
  {  
      age =age2;  
  }  
  -(NSInteger)getAge  
  {  
      return age;  
  }  
 @end

test.m

 //文件存为utf-8格式  
 #import <Foundation/Foundation.h>   
 #import "People.m"  

 int main(int arvc, char* argv[])   
 {   
    NSString *domain = @"wudimei.com杨庆荣";  

    NSLog(@"domain:%@ ,length:%d",[domain uppercaseString] , [domain length]);   
    People *people= [[People alloc]init];//初始化自定义类People  
    NSString *name = [[NSString alloc]init];  
    name=@"yqr杨庆荣";  
    [people setName:name];  
    [people setAge:28];  
    NSLog(@"name:%@ , age: %d", [people getName] ,[people getAge]);  
    return 0;   
 }   

编译命令:

gcc -o test test.m -I/GNUstep/System/Library/Headers/ -fconstant-string-class=NSConstantString -L/GNUstep/System/Library/Libraries -lobjc -lgnustep-base && ./test.exe  

上一篇: android笔记:点击按钮显示文本
下一篇: gnustep:object-c继承