安裝xcode
從App Store下載xcode
檢查Swift版本依賴
eval "$(curl -sL check.vapor.sh)"
? Compatible Xcode
? Compatible with Vapor 2
安裝Vapor
安裝homebrew
添加Homebrew Tap
在macOS安裝Vapor的tap后,它會讓homebrew擁有安裝所有package的權(quán)限烘贴。
MrleedeMBP:YorkLee mrlee$ brew tap vapor/homebrew-tap
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Cleaning up /Library/Caches/Homebrew...
==> Migrating /Library/Caches/Homebrew to /Users/mrlee/Library/Caches/Homebrew..
==> Deleting /Library/Caches/Homebrew...
==> Updated Formulae
cromwell gutenberg nco sslyze wget
duplicity ldns pwntools superlu
emscripten mercurial saldl transmission
gcc mingw-w64 socat w3m
==> Deleted Formulae
pcap_dnsproxy
MrleedeMBP:YorkLee mrlee$ brew update
Already up-to-date.
安裝vapor
brew install vapor
==> Installing vapor from vapor/tap
==> Downloading https://github.com/vapor/toolbox/releases/download/3.1.3/macOS-s
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws
######################################################################## 100.0%
?? /usr/local/Cellar/vapor/3.1.3: 4 files, 17.0MB, built in 24 seconds
常用命令
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.
cloud-beta [BETA!] Commands for interacting with Vapor Cloud.
heroku Commands to help deploy to Heroku.
provider Commands to help manage providers.
創(chuàng)建第一個工程
MrleedeMBP:Desktop mrlee$ vapor new hello
Cloning Template [Done]
Updating Package Name [Done]
Initializing git repository [Done]
**
**~~**
**~~~~~~**
**~~~~~~~~~~**
**~~~~~~~~~~~~~~**
**~~~~~~~~~~~~~~~~~~**
**~~~~~~~~~~~~~~~~~~~~~~**
**~~~~~~~~~~~~~~~~~~~~~~~~**
**~~~~~~~~~~~~~~~~~~~~~~~~~~**
**~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
**~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
**~~~~~~~~~~~~~~~~~~~~~++++~~~**
**~~~~~~~~~~~~~~~~~~~++++~~~**
***~~~~~~~~~~~~~~~++++~~~***
****~~~~~~~~~~++++~~****
*****~~~~~~~~~*****
*************
_ __ ___ ___ ___
\ \ / / /\ | |_) / / \ | |_)
\_\/ /_/--\ |_| \_\_/ |_| \
a web framework for Swift
Project "HelloWorld" has been created.
Type `cd HelloWorld` to enter the project directory.
Use `vapor cloud deploy` to host your project for free!
Enjoy!
在創(chuàng)建工程時候可以指定模板
- API --template=api 使用Fluent數(shù)據(jù)庫提供json的api
- Web --template=web 使用leaf模版創(chuàng)建的html網(wǎng)站
- Auth --template=auth https://github.com/vapor/auth- template
- Nodes-Vapor --template=nodes-vapor
- Truemetal --template=truemetal
- UserRepo --template=user/repo http://github.com/user/repo
- FullPath --template=http://example.com/repo-path
如果我們要創(chuàng)建一個網(wǎng)站,則可以用下面命令:
vapor new hello --template=web
Xocde打開工程
- cd 到工程目錄 例如:cd hello
- 利用命令打開Xcode
MrleedeMBP:hello mrlee$ vapor xcode
Generating Xcode Project [Done]
Select the `Run` scheme to run.
Open Xcode project?
y/n> y
運(yùn)行
結(jié)果
最后
歡迎廣大iOS開發(fā)者入坑,技術(shù)交流QQ群:431296189