这是一个收集和整理Swift实用工具和扩展的代码库,旨在提供可复用的Swift代码组件。
- UI: UI相关的扩展和组件
- Networking: 网络请求相关的工具
- Utilities: 通用工具函数
- Extensions: Swift标准库的扩展
在您的Package.swift
文件中添加以下依赖:
dependencies: [
.package(url: "https://github.com/your-username/swift-toolkit.git", from: "1.0.0")
]
- 在Xcode中打开您的项目
- 选择 File > Add Packages...
- 在搜索框中输入:
https://github.com/your-username/swift-toolkit.git
- 选择版本规则
- 点击 Add Package
import SwiftToolkit
// 使用UI扩展
let view = UIView()
view.addCornerRadius(10)
// 使用网络工具
let networkManager = NetworkManager()
networkManager.request(url: "https://api.example.com") { result in
// 处理结果
}
// 使用工具函数
let date = Date()
let formattedDate = date.formattedString()
欢迎提交Pull Request来贡献您的代码。请确保:
- 代码符合Swift风格指南
- 添加适当的文档注释
- 包含单元测试
- 更新README.md(如果需要)
MIT License
To use the Google Fonts API, you need to set up your API key:
- Get your Google Fonts API key from the Google Cloud Console
- Create a
.env
file in the project root directory - Add your API key to the
.env
file:GOOGLE_FONTS_API_KEY=your_api_key_here
Never commit your actual API key to the repository. The .env
file is already in .gitignore
to prevent accidental commits.
- Clone the repository
- Copy
.env.example
to.env
and add your API key - Build and run the project
-
复制环境变量模板文件:
cp .env.example .env
-
编辑
.env
文件,添加您的 API keys:GOOGLE_FONTS_API_KEY=your_api_key_here
- 在 Xcode 中设置环境变量:
- 选择您的 target
- 进入 "Edit Scheme"
- 选择 "Run" 配置
- 在 "Arguments" 标签页的 "Environment Variables" 部分添加:
GOOGLE_FONTS_API_KEY=your_api_key_here
如果您使用 CI/CD 服务,请在相应的平台设置环境变量:
- GitHub Actions: 在仓库的 Settings > Secrets 中添加
- GitLab CI: 在 Settings > CI/CD > Variables 中添加
- Bitrise: 在 Workflow Editor > Env Vars 中添加
- 永远不要提交包含实际 API key 的
.env
文件 - 定期轮换您的 API keys
- 使用最小权限原则设置 API key 的访问权限
- 在开发和生产环境使用不同的 API keys
- 克隆仓库
- 设置环境变量
- 构建和运行项目