Swift服務端開發系列完整版
swift服務端開發系列
一、拉取git倉庫
1、初始化配置git
git init
2、配置緩存密碼
git 默認緩存密碼15分鐘:
git config --global credential.helper cache
設置 git 默認的密碼緩存時限,命令:
# 設置緩存時限為 1 小時(以秒為單位進行設置)
git config --global credential.helper 'cache --timeout=3600'
二、拉取遠端倉庫代碼
1、clone 遠端項目
git clone https://e.coding.net/*******/AimTrendServerSide.git
輸入賬號和密碼(略過),輸入密碼前記得切換輸入法到英文輸入法。
進入到項目所在目錄
cd AimTrendServerSide/
2、vapor拉取依賴庫
查看 vapor 操作命令
vapor --help
vapor主要的操作指令
Commands:
new Creates a new Vapor application from a template.
Use --template=repo/template for github templates
Use --template=full-url-here.git for non github templates
Use --web to create a new web app
Use --auth to create a new authenticated API app
Use --api (default) to create a new API
build Compiles the application.
run Runs the compiled application.
fetch Fetches the application's dependencies.
update Updates your dependencies.
clean Cleans temporary files--usually fixes
a plethora of bizarre build errors.
test Runs the application's tests.
xcode Generates an Xcode project for development.
Additionally links commonly used libraries.
version Displays Vapor CLI version
cloud Commands for interacting with Vapor Cloud.
heroku Commands to help deploy to Heroku.
provider Commands to help manage providers.
建議,先用 clean 命令清除不必要的緩存數據
vapor clean
拉取依賴庫
vapor fetch
升級依賴庫,更新到最新庫
vapor update
三、運行swift項目
1、編譯項目
swift build
2、運行項目
swift run
四、遇到問題
1、Foundation 引用的坑
為了支持跨平臺和不必要的引用,蘋果將Foundation庫進行了拆分,將 Runtime、URLSession、Formatters、Predicates、XML、Collections、RunLoop、String、Number、DateTime、Model、Notifications、UserDefaults等相關的功能拆分出來,放在了一個新庫FoundationNetworking中。
對于在linux 系統上編譯找不到URLSession、String的問題,需要引入 FoundationNetworking,標準寫法如下:
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
注意:蘋果已將 FoundationNetworking 庫源碼打包到ubuntu對應的二進制包中,不需要額外導入。
推薦閱讀:Swift服務端開發系列完整版