me icon indicating copy to clipboard operation
me copied to clipboard

Swift 语法笔记 (Part 2)

Open nonocast opened this issue 3 years ago • 0 comments

Swift的project结构和package manager的形式总体上来说了javascript相似,npm/yarn init类似swift init, 然后swift package manger (Swift PM)类似npm repo。又因为Swift是强类型语言,所以swift/swiftc和java/javac是一个意思。 (更新: 此处描述有错误,请参考 #246)

swift and swiftc

  • swift: swift is an interactive environment (REPL) for Swift.
  • swiftc: swift compiler

app.swift

print("hello, world")
  • 可以通过swift app.swift直接解释运行
  • 也可以通过swiftc app.swift生成app可执行文件

Package Manager Tools

swift在swiftc的基础上提供了swift build, swift run和swift test,某种程度上可以理解为在语言层面整合npm/yarn。

通过swift init 可以生成library和execution两种package,大多数情况我们只是在Xcode中使用,这部分初步了解即可。

直接看Swift.org - Getting Started#Using the Package Manager

C Interoperability

调用C/C++的library,这个后续会用到,这里先留个坑。

How to call C code from Swift - The.Swift.Dev. C Interoperability | Apple Developer Documentation

参考阅读:

nonocast avatar Jul 27 '21 17:07 nonocast