first USAGE of GNUstep

[Project] demo [cmd] ls -R

.:
GNUmakefile
main
Readme.md
r.sh
src

./src:
Fraction.h
Fraction.m
main.m
Person.h
Person.m

Person.h

#import <Foundation/Foundation.h>
#import <stdio.h>
@interface Person:NSObject{
  // instance variable
  int age;
  int sex;
}
- (void)getAge;

@end

Person.m


#import "Person.h"
@implementation Person
- (void)getAge {
  printf("%d\n", age);
}
@end

Fraction.h

#import <Foundation/Foundation.h>

@interface Fraction : NSObject {
@protected
  int numerator;
  int denominator;
}
- (void)print;
- (id)set:(int)n over:(int)d;
- (id)init;
@end

Fraction.m

#import "Fraction.h"
@implementation Fraction

- (void)print {
  NSLog(@"print");
}

- (id)init {
  self = [super init];
  if (self != nil) {
    self->denominator = 1;
    self->numerator = 1;
  }
  return self;
}

- (void)set:(int)n over:(int)d {
  self->denominator = d;
  self->numerator = n;
}
@end

main.m

#import "Fraction.h"
#import "Person.h"
#import <AppKit/AppKit.h>
#pragma mark main1
int main1() {
  NSAutoreleasePool *pool = [NSAutoreleasePool new];
  Fraction *f = [Fraction init];
  NSLog(@"fuc");

  NSSet *set1 = [[NSSet alloc] initWithObjects:@"one", @"two", nil];
  NSLog(@"fuck you");
  NSArray *arr1 = nil;
  NSSet *set2 = [NSSet new];
  NSString *str = @"hell world";
  NSLog(str);
  int i = 2;
  NSLog(@"%d", i);
  printf("%d\n", i);
  [f release];

  [pool drain];

  return 0;
}

#pragma mark struct Hello
typedef struct Hello {
  int a;
} Hello;
void sayHello(struct Hello *me) {
  printf("a: %d\n", me->a);
  printf("yas\n");
}
#define PI 3.14

#pragma mark test case
void test1() {
  int score = 10;
  if (score < 20) {
    NSLog(@"static load failed");
  } else if (score >= 60) {
    NSLog(@"nice");
  } else {
    NSLog(@"full score");
  }
}

#pragma mark
int main2() {
  NSAutoreleasePool *pool = [NSAutoreleasePool new];
  // begin section
  Person *per1 = [[Person alloc] init];
  per1->age = 1;
  [per1 getAge];

  Hello h1;
  h1.a = 1;
  sayHello(&h1);
  printf("PI: %d\n", PI);

  // test code
  printf("\n*************test code***************\n");
  test1();
  // before a end
  [pool drain];
  return 0;
}

#pragma mark
int main() {
  CREATE_AUTORELEASE_POOL(pool);
  printf("yas\n");
  RELEASE(pool);
}

GNUmakefile

GNUSTEP_MAKEFILES = /usr/share/GNUstep/Makefiles
SRC_DIR = ./src
include ${GNUSTEP_MAKEFILES}/common.make
APP_NAME = main
main_HEADERS = $(SRC_DIR)/Fraction.h $(SRC_DIR)/Person.h
main_OBJC_FILES = $(SRC_DIR)/main.m $(SRC_DIR)/Fraction.m $(SRC_DIR)/Person.m
main_RESOURCE_FILES =
include ${GNUSTEP_MAKEFILES}/application.make

r.sh

#!/bin/sh
make
echo -e "\n\n\n"
echo "************************************"
echo "************************************"
echo "************************************"
openapp ./main.app
echo -e "\n\n\n"
echo "***************** start cleaning **************************"
make clean

[COMMAND] ./r.sh

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值