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

Basics - variables - datatypes

//import UIKit
//import Cocoa
/*var str = "Hello, playground"
print(str)

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

// Var Able to change value of it
var Age = 10;
print (Age);
Age = 50;
print (Age);
// Let Not Able to change value of it
let name = "Koky";
print (name);

var num = 10;
print(num)

var dou = 20.3
print(dou)


var nametxt = "Mariam"
var height = 1.5
let greeting = "Hello, "

print (greeting + nametxt)
print (name + " is " + String(height) + "m " + "tall")

// Data Types
var Intval : Int = 20;
var UIntval : UInt = 2022222;
var Floatval :Float = 230.5
var Doubleval : Double = 50.36
var Stringval : String = "eman"
var boolval : Bool = true
var Characterval : Character = "x"



print(UIntval, Intval , Floatval , Doubleval , Stringval , boolval,Characterval)
// Create Own DataType 
typealias Feet = Int
var distances: Feet = 100
print(distances)

var remainder = -13 % 9
print(remainder)
var quotient = 15 / 2
print(quotient)

var distance = 200 //in km
var time = 2.3 //in hours
var speed = Double(distance)/time
print (speed)

print("Items to print \n", separator: "Value \n" , terminator: "Value")
print("\nValue one","Value two", separator: " \nNext Value" , terminator: " \nEnd")

// You can declare variable as Variable Declaration
var intalx = 10;
// You can declare variable as Type Annotations
var intalxx : Int = 10;

var varA = "Godzilla"
var varB = 1000.00

print("Value of \(varA) is more than \(varB) millions")

// Declare Value as optical that not mandatory assign value to parameter
var perhapsInt: Int?
var nnn : Int? = nil


var Inta : Int?
var perhapsStr : String? =  nil
perhapsStr = "Hellow Every Body"

if perhapsStr != nil {print(perhapsStr)} 
else { print("myString has nil value")}

var myString  : String?
myString = "no one else"
if myString != nil{print(myString)}
else{print("myString  Is Nil")}

if test == nil {print("Test Is Nil")}
else {print(test)}
*/
var test : String!
test = "Hello Emy"

if let yourString = test {
   print("Your string has - \(yourString)")
} else {
   print("Your string does not have a value")
}
var error501 = (errorCode: 501, description: "Not Implemented")
print(error501.errorCode)   // prints 501.


let stringL = "Hello\tWorld\n\nHello\'Swift 4\'"
print(stringL)


Advertisements
Loading...

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