programing

Swift를 웹 프로그래밍 언어로 사용할 수 있습니까?

nasanasas 2020. 12. 1. 08:09
반응형

Swift를 웹 프로그래밍 언어로 사용할 수 있습니까?


웹 사이트 / 웹 앱을 구축하기위한 프로그래밍 언어로 Swift를 기술적으로 사용할 수 있습니까?


업데이트 : 많은 사람들이이 작업을하고있는 것 같습니다.


Apple의 공식 지원 : https://swift.org/server-apis/


물론 이론적으로.

일반 텍스트를 출력 할 수있는 모든 프로그램은 Swift를 포함하는 CGI (Common Gateway Interface)에도 사용할 수 있습니다.

따라서 예, 웹 프로그래밍에 Swift를 사용할 수 있습니다. 그러나 현재로서는이 프로세스를 쉽게 수행 할 수있는 추가 라이브러리 (예 : PHP 또는 EJB / JSP에 있음)가 없습니다. Vapor 과 같은 Swift 용으로 유명한 웹 프레임 워크를 살펴보십시오 .


이 주제가 더 이상 얼마나 활발한 지 잘 모르겠지만, 앞으로 누군가이 주제를 발견하게 될 경우를 대비해 Swift에서 FastCGI 애플리케이션을 작성하기위한 프레임 워크 작업을 시작했음을 여기에서 발표하고 싶습니다.

물론 Objective-C 웹 프레임 워크를 사용할 수 있으며 (비록 적지 만) CGI에 의해 역류 될 HTML 문자열을 덤프하는 스크립팅 언어로 Swift를 확실히 사용할 수 있습니다. 그러나 (나는 여기에서 모든 철학을 다룰 것입니다.) 나는 감히이 용어를 사용한다면 그러한 접근 방식에 대한 정착이 그다지 "스위프트"와 같지 않다고 생각합니다. 스위프트 디자이너는 (사실, 나는 C 확실히는 (의 제한)없이 "그냥"의 Obj-C보다 더 있는지 확인하는 문제를 많이 겪었 거의 가 너무 자주 잘못 인용이기 때문에 그 소원들은 말했다하지 않았다). Swift는 또한 Obj-C보다 기능적 계열에 훨씬 더 가깝습니다 (단단한 객체 방향을 유지하고 Python과 같은 스크립트 기능을 추가하도록 관리함). 이것은 제가 탐구해야 할 완전히 새로운 디자인 선택의 세계를 열어줍니다. 또한,

이 모든 것을 말하면, Swift로 웹 앱을 매우 높은 수준으로 작성할 수있는 모듈 식 "마이크로 프레임 워크"를 직접 만들었습니다. 이 글을 쓰는 시점에서 나는 그것을 기능적 개념 증명으로 분류했지만 여전히 내가 원하는만큼 추상적이지 않고 실제 사용에 필요한 여러 주요 기능이 누락되었습니다. 물론 기부를 환영합니다. 누군가 이것이 도움이되기를 바랍니다. https://github.com/ianthetechie/SwiftCGI


Swift는 웹 프로그래밍 언어로 완벽하게 작동합니다. 스크립팅 (빠른 개발 또는 간단한 작업을 위해)과 같은 파이썬을 수행하고 나중에 XCode (속도를 위해)로 동일한 코드를 컴파일 할 수 있습니다.

다음 스크립트를 Mac의 / Library / WebServer / CGI-Executables / TestCGI에 복사합니다 (OSX Mavericks 또는 Xcode 6.x가 설치된 Yosemite). 와 그것을 실행합니다 chmod +x TestCGI. httpd 시작된 통화로 http://localhost/cgi-bin/TestCGI. 호출 매개 변수가 에코됩니다.

#!/usr/bin/env xcrun swift

import Foundation

print("Content-Type: text/html")
print("Content:")
print("")
print("1. Process.argument(s):<br />")
for s in Process.arguments {
    print(s + "<br />")
}
print("<br />")

let env: Dictionary = NSProcessInfo().environment

if let requestMethod = env["REQUEST_METHOD"] {
    print("2. Request method is: \(requestMethod)<br /><br />")
}

print("3. Number of environment variables: \(env.count)<br /><br />")

print("4. List environment:<br />")
for key in env.keys {
    print("\(key) == \(env[key]!)<br />")
}

Apple은 이제 Linux 서버에서 컴파일 할 수 있도록 Foundation 라이브러리 ( https://github.com/apple/swift-corelibs-foundation )를 오픈 소스로 제공했습니다 (12/03/15) .


예, Swift에서 웹 앱을 만들 수 있습니다. Tailor 는 그렇게 할 수있는 웹 프레임 워크 중 하나입니다. 소스 코드는 Github에 있습니다.


그래 넌 할수있어.

Swift does the same as ObjectiveC, but does it easier. Therefore, you could use a very simple CGI-Interface (see http://www.sveinbjorn.org/objectivecgi) to analyse and answer client requests (both GET and POST) on the server side.

Since Swift is strong in string manipulation, it will be somewhere between ObjectiveC and PHP/Perl in terms of abstraction. For many purposes, a SQLite or MySQL frontend isn't even needed. Just drop your data into some text file on the server.


As per the other answers, you can use Apple Swift in any number of ways as part of a web site/app implementation.

Additionally however, other companies are also developing Swift language compilers which extend the capabilities even further. For example, RemObjects recently announced that in the next major release of their Elements compiler, they would be introducing a new compiler front-end dubbed "Silver", which is a Swift compiler.

As a front end onto their existing compiler technology which already supports ObjectPascal (Oxygene) and C# (Hydrogene), this means that you will be able to develop .NET and Java applications (including Android) using the Swift language. With .NET support, that obviously means you could use Swift to create an ASP.NET web site/app.

Note that this is a native compiler for each platform - there is no source code translation/cross compilation or platform abstraction or compatibility framework involved, as there is with (for example) Xamarin. The RemObjects compiler produces platform specific, native code (i.e. MSIL for .NET, Java Bytecode for JVM etc etc). It also allows the developer to consume platform libraries natively. i.e. when developing for Cocoa, Cocoa classes are exposed directly into the language, ditto Java classes when developing for Java, .NET framework for .NET etc.

This is the case whether you are using the ObjectPascal, C# or Swift language front-ends (and you can mix and match languages in a project, if you so desire).

The 8.0 release has been in beta for a while already so existing Elements licensee's have been playing with it already. :)


In the article Cocoa with Love, you could find an example of HTTP server. It is written in Obj-C: http://www.cocoawithlove.com/2009/07/simple-extensible-http-server-in-cocoa.html

Here is my attempt to create a swift version: https://github.com/grzegorzleszek/HTTPSwiftServer

Browsing the web, I've found really nice swift version of HTTP server. It is worth to have a look: https://github.com/glock45/swifter

참고URL : https://stackoverflow.com/questions/24235974/can-you-use-swift-as-a-web-programming-language

반응형