Web Coding in Swift
Unfortunately, Swift is not installed on this server. Functions are disabled.
Swift is Apple's new language intended to make app development easier than using Objective-C. However, there are many features not yet available in Swift, so sometimes we have to make Objective-C function calls that use the Cocoa library to do I/O and other operations.
Swift is a compiled language, but modules can also be executed as scripts. I tried to run the code using this line, which I put at the top of each file:
#!/usr/bin/env xcrun swift
When running the module as scripts, it becomes difficult to link my own library code. So, instead, I first compile the common module like this:
xcrun swiftc \ -emit-library \ -module-name common \ -emit-module common.swift \ -sdk $(xcrun --show-sdk-path --sdk macosx)
Then I compile and link the remaining modules using this script, which I named maks (for Make Swift). This command tells Swift to look for the include files and resulting libraries in this current directory. It also saves the executable file with the cgi file extension.
#!/bin/sh /usr/bin/env xcrun swiftc -o $1.cgi -I "." -L "." -lcommon \ -module-link-name common \ -sdk $(xcrun --show-sdk-path --sdk macosx) $1.swift
Useful Links
Apple Documentation
- The Swift Programming Language: The Basics
- The Swift Programming Language: Control Flow
- The Swift Programming Language: Collection Types
- The Swift Programming Language: Strings and Characters
- Swift Resources
- NSFileManager : moveItemAtPath
- NSFileManager Class Reference
- NSOutputStream : outputStreamToFileAtPath
Strings
- Swift replace substring regex
- How to replace characters in Swift string
- How do I check if a string contains another string in Swift?
- String formatting of a double
- Split string into an array
- Convert string to int
- String reference guide for Swift
- Get the length of a string
- Swift apply .uppercaseString to only the first letter of a string
- Get nth character of a string in Swift programming language
- Convert string to float
- Proper URL (Percent) Encoding in iOS
- Swift string trim method
Files
- Simple way to read local file using Swift
- Read a file line-by-line in Swift
- Swift: iterate through files in a folder and its subfolders
- Writing a String to an NSOutputStream in Swift
- How to open file and append a string to it in swift
- Working with Files in SWift on iOS 8
- Working with iOS File Management using Swift
More
- Can you use Swift as a web programming language?
- How can I get an environment variable from Xcode in my app
-
xcrun swift on command line generate
:0: error: could not load shared library - Missing argument for parameter #1 in call error for function with no params. Swift
- Ultimate guide to learning Swift in one day
- Could not find an overload for '*' that accepts the supplied argument
- If condition failing with expression too complex
- inferred to have type AnyObject which may be unexpected
- Xcode 6, Swift - read standard input (console) to string