Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute Swift Online

import Foundation
import Glibc
 
var error501 = (501, "Not implemented")
var s1:String = "n1"
var s2 = "n2"
let c1:Character = "a"
var arrI = [5,6,3,10,8]
var nul:Bool? = nil
print("The code is \(error501.0)")
print("The definition of error is = \(error501.1)")

print(s1, s2, separator: " - ", terminator: " end ")
s1.append(c1)
print(s1)

print()
print(arrI)
var i = 0
for _ in arrI {
    print(arrI[i])
    i+=1
}
print(nul as Any)
print()

let evens: Set = [10,12,14,16,18]
let odds: Set = [5,7,9,11,13]
let primes = [2,3,5,7]
print(odds.union(evens).sorted())
print(odds.intersection(evens).sorted())
print(odds.subtracting(primes).sorted())
print()
func display(no1: Int) -> Int {
   let a = no1
   return a
}

print(display(no1: 100))
print(display(no1: 200))

func sum(a: Int, b: Int) -> Int {
   return a + b
}
var addition: (Int, Int) -> Int = sum
print(addition(40, 89))

let divide = {
   (val1: Int, val2: Int) -> Int in 
   return val1 / val2 
}
print(divide(200, 20))

var count:[Int] = [5, 10, -6, 75, 20]
let descending = count.sorted(by: { n1, n2 in n1 > n2 })
let ascending = count.sorted(by: { n1, n2 in n1 < n2 })

print()
print(descending)
print(ascending)

print()
let sub = {
   (no1: Int, no2: Int) -> Int in
   return no1 - no2 
}
let digits = sub(10, 20)
print(digits)

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.