Swift服務端開發系列:(四)Ubuntu部署Swift服務端

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服務端開發系列完整版

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 這個電影的恐怖之處在于人性,警察們為了追查一位殺人魔而去求助于另外一位殺人魔。女性在職場中受限和碰壁,人類的孤獨和...
    IAMQING閱讀 1,005評論 0 0
  • 一、基本指令 1. v--cloak 一般與 display: none; 結合使用。作用:解決初始化較慢時導致的...
    養樂多__閱讀 598評論 0 0
  • 當感到傷痛時,你怎樣保護自己? 有的人通過“好人”的形象保護自己,有的人讓自己變得麻木、絕望,有的人裝“可憐”,有...
    曼曼_異想閱讀 322評論 0 1