var str = "Hello, Playground" print(str) var NameFirst = "Bob" var email = "[email protected]" var pass = "123abc" email = "[email protected]" pass = "2919178181hsjs@" var Life = 150 var HeartCount = 3 var PersonPicture = "Picture Of Person" // Person Gets Hit HeartCount = 2 // again HeartCount = 1 let database = "databaser1234" var number: Int = 200 var numbertwo: Int = 1000 var value: Double = 20.35 var value1: Int = 23454 var value2: String = "Im from germany" var value3: Double = 30.345 func nameofit() { print("check") print("login") print("load posts") print("show") } nameofit()
Write, Run & Share Swift code online using OneCompiler’s Swift online compiler for free. It’s a fast and user-friendly platform to explore Swift programming right from your browser. Ideal for students, beginners, and professionals looking to prototype or test Swift code.
Swift is a powerful and intuitive programming language developed by Apple for iOS, macOS, watchOS, and tvOS app development. It's designed to be safe, fast, and expressive, with modern features like optionals, closures, and type inference.
The following is a simple Swift program that prints a greeting:
import Foundation
print("Hello, OneCompiler!")
OneCompiler’s Swift editor supports standard input via the I/O tab. Here’s a sample Swift program that takes a user’s name and prints a greeting:
import Foundation
if let name = readLine() {
print("Hello, \(name)!")
}
var age = 25 // Mutable variable
let name = "Swift" // Constant
Type | Description |
---|---|
Int | Whole numbers |
Double | Decimal numbers |
String | Sequence of characters |
Bool | true or false |
Array | Ordered collection |
Dictionary | Key-value pairs |
let score = 75
if score >= 50 {
print("Pass")
} else {
print("Fail")
}
for i in 1...5 {
print(i)
}
var i = 1
while i <= 5 {
print(i)
i += 1
}
var j = 1
repeat {
print(j)
j += 1
} while j <= 5
func greet(name: String) {
print("Hello, \(name)!")
}
greet(name: "OneCompiler")
func add(a: Int, b: Int) -> Int {
return a + b
}
This guide provides a quick reference to Swift programming syntax and features. Start writing Swift code using OneCompiler’s Swift online compiler today!