Swift is friendly to new programmers. It is the first industrial-quality systems programming language that is as expressive and enjoyable as a scripting language.
The compiler is optimized for performance, and the language is optimized for development, without compromising on either. It’s designed to scale from “hello, world” to an entire operating system.
print("Hello, world!")If you have written code in C or Objective-C, this syntax looks familiar to you—in Swift, this line of code is a complete program. You don’t need to import a separate library for functionality like input/output or string handling. Code written at global scope is used as the entry point for the program, so you don’t need a main() function. You also don’t need to write semicolons at the end of every statement.
var myVariable = 42
myVariable = 50
let myConstant = 42- Use
varto declare variables andletto declare constants
let implicitInteger = 70
let implicitDouble = 70.0
let explicitDouble: Double = 70- Variables cannot change types once declared, but often do not need explicit type information
final int[] individualScores = [75, 43, 103, 87, 12];
int teamScore = 0;
for( int score : individualScores ) {
if (score > 50) {
teamScore += 3;
} else {
teamScore += 1;
}
}
System.out.printf("%d\n",teamScore)let individualScores = [75, 43, 103, 87, 12]
var teamScore = 0
for score in individualScores {
if score > 50 {
teamScore += 3
} else {
teamScore += 1
}
}
print(teamScore)- The Swift Programming Language. Apple Inc. Used under a Creative Commons Attribution 4.0 International (CC BY 4.0) License.