Swift is an open source programming language created in 2014 by Chris Lattner.
#21on PLDB | 10Years Old | 1mRepos |
git clone https://github.com/apple/swift
Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. for iOS, macOS, watchOS, tvOS, and Linux. Swift is designed to work with Apple's Cocoa and Cocoa Touch frameworks and the large body of existing Objective-C (ObjC) code written for Apple products. Read more on Wikipedia...
// Type your code here, or load an example.
func square(n: Int) -> Int {
return n * n
}
print("Hello, world!")
print("Hello World")
// Hello world in Swift
println("Hello, world!")
println("Hello, world")
var someSortOfPrintableObject: SupportsToString
...
print(someSortOfPrintableObject.toString())
associatedtype class deinit enum extension func import init inout internal let operator private protocol public static struct subscript typealias var break case continue default defer do else fallthrough for guard if in repeat return switch where while as catch dynamicType false is nil rethrows super self Self throw throws true try #column #file #function #line #available #column #else#elseif #endif #file #function #if #line #selector associativity convenience dynamic didSet final get infix indirect lazy left mutating none nonmutating optional override postfix precedence prefix Protocol required right set Type unowned weak willSet
Feature | Supported | Example | Token |
---|---|---|---|
Standard Library | ✓ | print("Hello, World!") | |
Binary Literals | ✓ | // 0b[01_]+ | |
Integers | ✓ | // [0-9][0-9_]* | |
Floats | ✓ | // [0-9][0-9_]*(\.[0-9_]+[eE][+\-]?[0-9_]+|\.[0-9_]*|[eE][+\-]?[0-9_]+) | |
Hexadecimals | ✓ | // 0x[0-9a-fA-F_]+ | |
Octals | ✓ | // 0o[0-7_]+ | |
Conditionals | ✓ | ||
Access Modifiers | ✓ | ||
Switch Statements | ✓ | ||
Exceptions | ✓ | ||
Classes | ✓ | ||
While Loops | ✓ | ||
Booleans | ✓ | true false | |
Case Sensitivity | ✓ | ||
MultiLine Comments | ✓ | /* A comment */ | /* */ |
Print() Debugging | ✓ | ||
Line Comments | ✓ | // A comment | // |
Type Inference | ✓ | ||
Operator Overloading | ✓ | ||
Interfaces | ✓ | protocol MyProtocol { init(parameter: Int) var myVariable: Int { get set } var myReadOnlyProperty: Int { get } func myMethod() func myMethodWithBody() } extension MyProtocol { func myMethodWithBody() { // implementation goes here } } | |
File Imports | ✓ | import UIKit import UIKit.UITableViewController let tvc = UITableViewController() let vc = UIViewController() let label = UILabel() | |
Comments | ✓ | ||
Single Dispatch | ✓ | ||
Strings | ✓ | "hello world" | " |
Assignment | ✓ | let label = UILabel() | |
Case Insensitive Identifiers | X | ||
Semantic Indentation | X | ||
Variable Substitution Syntax | X |