Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift: QuickStart #416

Open
hhstore opened this issue Jan 6, 2024 · 7 comments
Open

Swift: QuickStart #416

hhstore opened this issue Jan 6, 2024 · 7 comments

Comments

@hhstore
Copy link
Owner

hhstore commented Jan 6, 2024

📖 Abstract:

  • ✅ Swift QuickStart.

💯 Related:

@hhstore
Copy link
Owner Author

hhstore commented Jan 6, 2024

Swift 教程:

  • 偶尔需要写一点 swift 代码.
  • 简单记录一下安装环境的配置过程.

官方文档:

swift 版本:

# 当前最新版本: 
swift: 5.9
xcode: 15

中文翻译:

资源:

社区讨论:

@hhstore
Copy link
Owner Author

hhstore commented Jan 6, 2024

Swift 安装:

  • Mac下, 安装xcode, 默认内置了 swift, 不过版本可能不是最新. (升级 xcode, 自动升级 swift)
  • 查看 swift, 确保已经安装:
# macOS: 12.6.2
╰─>$ xcodebuild -version                                                       12:55:16
Xcode 14.2
Build version 14C18

╰─>$ swift --version                                                                                                                   
swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
Target: x86_64-apple-macosx12.0

Swift 创建一个新项目:

  • 生成指令:
mkdir try-swift/

cd try-swift/;

# 初始化, 默认生产一堆模板文件
swift package init --type=executable
  • 生成的模板项目结构:
tree try-swift/ -L 3                                                                                                              

try-swift/
├── Package.swift
├── README.md
├── Sources
│   └── try-swift
│       └── try_swift.swift
└── Tests
    └── try-swiftTests
        └── try_swiftTests.swift

5 directories, 4 files
  • 编译+运行:
cd try-swift/

# 编译+运行: 打印 hello
swift run
  • 运行单元测试:
cd try-swift/

swift test

Swift 配置开发环境:

Swift + xcode 开发环境:

  • 默认安装 xcode, 开箱即用.
  • 参考 Apple 官方的 SwiftUI 教程.

Swift + vscode 开发环境:

  • 使用 vscode, 只用安装一个插件.
  • vscode 搜索 swift, 排第一的插件,装一下. 结束.
  • 此时的 vscode 具备代码索引能力. 基本可用.

@hhstore
Copy link
Owner Author

hhstore commented Jan 6, 2024

UI 框架:

🔥 Swift UI:

  • 支持 Apple 多端(macOS, iOS, TV, Watch 等)
  • 官方主推, bug 挺多. 但是, 要用起来.

🦄 官方:

状态:

参考:

视频:

🔥 UIKit:

  • 稳定, 可靠.

@hhstore
Copy link
Owner Author

hhstore commented Jan 6, 2024

1

3 similar comments
@hhstore
Copy link
Owner Author

hhstore commented Jan 6, 2024

1

@hhstore
Copy link
Owner Author

hhstore commented Jan 6, 2024

1

@hhstore
Copy link
Owner Author

hhstore commented Jan 6, 2024

1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant