OC完全兼容C, 代码后缀名一般习惯用 *.m 或 *.mm,按惯例从 "Hello,World!" 开始,我们编写一个 test.mm 文件如下:

#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{ 
  @autoreleasepool 
  {   
     NSLog(@"Hello, World!"); 
  }
  return 0;
}

  OC使用 clang 作为编译器,此外编译OC程序需要链接 Foundation 库(通过 -framework 参数来指定库),即编译命令如下:

clang test.mm -o test -framework Foundation

  swift 的示例代码为 test.swift 如下:

print("Hello,World!")

   执行命令为:

swift test.swift

 

相关文章:

  • 2021-09-01
  • 2021-11-27
  • 2021-12-07
  • 2021-05-28
  • 2021-05-10
  • 2021-09-28
  • 2021-11-08
  • 2021-04-30
猜你喜欢
  • 2021-11-24
  • 2021-05-23
  • 2021-09-06
  • 2021-12-29
  • 2021-11-25
  • 2021-12-04
相关资源
相似解决方案