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

Type Annotations

var varA = 42
print(varA)

var varB:Float

varB = 3.14159
print(varB)

variable declaration

var varA = 42
print(varA)

sampleswiftprogram

/* My first program in Swift 4 */
var myString = "Hello, World!"
print(myString)

type inference

// varA is inferred to be of type Int
var varA = 42
print(varA)

// varB is inferred to be of type Double
var varB = 3.14159
print(varB)

// varC is also inferred to be of type Double
var varC = 3 + 0.14159
print(varC)

type safety

var varA = 42
varA = "This is hello"
print(varA)

typealiases

typealias Feet = Int
var distance: Feet = 100
print(distance)

type

typealias Feet = Int
var distance: Feet = 100
print(distance)

sample

import Foundation
import Glibc
 
let player = ["rock", "paper", "scissors", "lizard", "spock"]
 
srandom(UInt32(NSDate().timeIntervalSince1970))
for count in 1...3 {
    print(count)
}
 
print(player[random() % player.count]);

test

var personne = Personne(nom: "Durand", prenom: "Paul", sexe: "m", age: 27, adresse: "94 rue machin")
var personne2 = personne

personne.age = 12

personne.affiche(valeurAAfficher: "Age")
personne2.affiche(valeurAAfficher: "Age")

Compile and Execute Swift Online

import Cocoa

/* My first program in Swift */
var myString = "Hello, World!"

println(myString)

Advertisements
Loading...

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