当前位置: 首页 > news >正文

use gnustep objective-c

first app

#import <Foundation/Foundation.h>int main(int argc, const char * argv[])
{NSAutoreleasePool *pool = [NSAutoreleasePool new];NSLog(@"first start");[pool drain];return 0;
}

tech

  1. 专注于概念,而不是迷失在语言技术细节中
  2. 编程语言的目的是成为一个更好的程序员; 也就是说,在设计和实现新系统以及维护旧系统方面变得更加有效

the basic structure of objc program has

  1. header preprocess
  2. interface
  3. implementation
  4. method
  5. variable
  6. declare and expression
  7. comment

use interface and implementation

#import <Foundation/Foundation.h>@interface SampleClass:NSObject
- (void)sampleMethod;
@end@implementation SampleClass
- (void)sampleMethod
{NSLog(@"hello from sample class");
}
@endint main()
{SampleClass *sampleClass = [[SampleClass alloc]init];[sampleClass sampleMethod];return 0;
}

type system

  1. basic integer set and float set
  2. enum type
  3. void type
  4. derive type include pointer, array, struct, union, function
// so far we still use Foundation
int main()
{NSLog(@"type int takes %d\n",sizeof(int));NSLog(@"Storage size for float : %d , maxval=%f \n", sizeof(float), FLT_MAX);int c_i = 1;NSInteger i = 1;NSLog(@"%d\n",i);
}

support c type variable and c type function

void test()
{printf("this is c type function\n");
}#define DEBUG YES
const int G_error_no = 1;// notice that upper case of const is a good style 
int main()
{  test();// cosume the c type functionNSLog(@"err no: %d\n",G_error_no);
}

基本运算符(算术,逻辑,位运算)的支持是和c保持一致,这里比较简单

  1. https://www.yiibai.com/objective_c/objective_c_operators.html#article-start

method in objc

  • (return_type) method_name:( argumentType1 )argumentName1
    joiningArgument2:( argumentType2 )argumentName2 …
    joiningArgumentn:( argumentTypen )argumentNamen {
    body of the function
    }
// skip the class declare and impl
// notice that java style is good style
// and joiningArgument just needed to take its place,but not a real name of argument
-(int)max:(int)num1 secondNumber:(int)num2{if (num1 > num2)return num1;else return num2;
}int main(){// call the method,for example using a classSampleClass *sampleClass = [[SampleClass alloc]init];int ret = [sampleClass max:1 secondNumber:2];printf("%d\n",ret);
}
// 函数参数按值传参和按引用/指针传参是支持的,有机会在深入一遍c语言

block is an instance (error with enable blocks using -fblocks)[notfix]

仅表示单个任务或行为单元而不是方法集合是有意义的(using block),它允许创建不同的代码段,这些代码段可以传递给方法或函数,就像它们是值一样。 块是Objective-C对象,因此它们可以添加到NSArray或NSDictionary等集合中。 它们还能够从封闭范围中捕获值,使其类似于其他编程语言中的闭包或lambda

returntype (^blockName)(argumentType);

returntype (^blockName)(argumentType)= ^{
};

use application.make

#filename must:GNUmakefile
GNUSTEP_MAKEFILES = /usr/share/GNUstep/Makefiles
SRC_DIR = . #this dir is source code directory
include ${GNUSTEP_MAKEFILES}/common.make
APP_NAME = main #name of application
main_OBJC_FILES = $(SRC_DIR)/main.m # a main.m file, if add .m file just add behind, we should have header as well
main_RESOURCE_FILES = # yet I dont know how to use
include ${GNUSTEP_MAKEFILES}/application.make
include ${GNUSTEP_MAKEFILES}/tool.make
include ${GNUSTEP_MAKEFILES}/Master/tool.make
# GNUstep reference may be in `linux mint`: /usr/share/GNUstep/Documentation
  1. then run make in the makefile folder

code reference

  • the above link

Todos

  1. read the rest post an get this file done
http://www.lryc.cn/news/111235.html

相关文章:

  • 8.15锁的优化
  • 单片机复位电路分析
  • 公文写作技巧:“三面镜子”写作提纲60例
  • useEffect中的函数会执行2次原因
  • 更新k8s环境支付系统支付证书
  • C#的yield
  • 外卖多门店小程序开源版开发
  • 打印图案、
  • # Windows 环境下载 Android 12源码
  • 【运维面试】Docker技术面试题总结
  • CNN成长路:从AlexNet到EfficientNet(01)
  • 使用IDEA操作Mysql数据库
  • ChatGPT下架官方检测工具,承认无法鉴别AI内容
  • Java通过实例调用getClass()方法、类名.class操作、通过运行时类获取其它信息
  • UE5+Paperzd问题
  • K8S系列文章之 自动化运维利器 Ansible
  • Julia 字典和集合
  • devops-发布vue前端项目
  • 使用正则表达式设置强密码
  • epoll、poll、select的原理和区别
  • 【学习笔记】Java安全之反序列化
  • 算法练习--leetcode 数组
  • 本地 shell无法连接centos 7 ?
  • C 语言的基本算术运算符 = + - * /
  • SQL注入实操三(SQLilabs Less41-50)
  • HOT77-买卖股票的最佳时机
  • CSS调色网有哪些
  • Day10-NodeJS和NPM配置
  • 线性代数 | 机器学习数学基础
  • Nios初体验之——Hello world!