搭建一个Perfect工程大致步骤如下:
创建工作空间引入Perfect库
设置工程
编码运行
准备工作:
下载Perfect库
推荐从git上下载源码,因为里面包含了可能用到的所有组件:
解压Perfect库的压缩包,安装xcode的Perfect模板
打开这个工程直接run就可以
打开Xcode—>File—>New—>WorkPlace
创建一个PerfectDemo的工作空间,穿件完成后会生成一个PerfectDemo.xcworkspace文件该文件就是一个Xcode的工作空间。


工程添加完成之后,开始设置我们的工程

setting.png
具体设置项目如下:
Skip Install = No
Deployment Location = Yes
Installation Directory = /PerfectLibraries
Installation Build Products Location = $(CONFIGURATION_BUILD_DIR)
所有的设置成功之后,开始编写服务端代码:
创建PerfectMain.swift文件:
先运行一下官方的示例代码:
import Foundation import PerfectLib // This is the function which all Perfect Server modules must expose.
// The system will load the module and call this function.// In here, register any handlers or perform any one-time tasks.
public func PerfectServerModuleInit() { // Install the built-in routing handler. // Using this system is optional and you could install your own system if desired.
Routing.Handler.registerGlobally() Routing.Routes["GET", ["/", "index.html"] ] = { (_:WebResponse) in return IndexHandler() }
// Check the console to see the logical structure of what was installed. print("(Routing.Routes.description)")}
class IndexHandler: RequestHandler {
func handleRequest(request: WebRequest, response: WebResponse) {
response.appendBodyString("Index handler: You accessed path (request.requestURI())") response.requestCompletedCallback()
}
}
代码编写完成之后,设置运行的Schema
选中PerfectDemo工程不要选到Perfect的库上去了
设置Excutable为我们之前添加的Perfect模板

editschame.png
设置完成之后,Run工程会启动一个PerfectServer Http程序,
表示我们的Perfect服务器已经启动,改程序面板可以设置服务器的端口号,ip,已经webroot目录等等

success.png
作者:Tywin_Zhang
链接:https://www.jianshu.com/p/a4741a89f679
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4549/viewspace-2820149/ ,如需转载,请注明出处,否则将追究法律责任。