Getting started with Swift – Mobile App Development, Android App Development, iphone App Development class="post-template-default single single-post postid-4443 single-format-standard wp-custom-logo"

Getting started with Swift

If you are comfortable with playground file I would strongly suggest to use this Interactive Playground File from Apple

Requirements

  • You need latest Xcode (Xcode 6 or up)
  • And for that you must have Yosemite (i.e. Mac OS 10.10 onwards)

Hello World

println("Hello, world!")

Variables and Constants

Define variables using var keyword var myVariable = value

Swift compiler will try to assign the type to myVariable based on the return type of value.

Define constants using let keyword let myConstant = value

If you do not want to assign a value yet to a variable then you have to hint the compiler of the object type. var myVariable: Dictionary

String interpolation

You can include a variable inside a string by using either of these syntax let myStringVar = "Hi"

Using + operator let myText = myStringVar + "!! Man"

Using () for string interpolation let myText2 = "\(myStringVar)!! Man"

Array Dictionary Tuples and other variable types

Arrays let todoItems = ["Go grocery", "Print important Docs", "Call Samantha"]

Dictionary let todoItems = ["important": ["Call Arun", "Reply to Samuel"], "not important": ["Go grocery", "Call Mom"]]

Tuples let myTuple = (3.14, "circle", "radius")

Tuples also contain multiple values but they can be any type. Array value must be of same type. Its helpful when a function returns multiple values.

Also tuples can also be defined as let (pi, shape, variable) = myTuple

and then you can access variables pi, shape and variables separately.

Constructors for base types

If you wish to initialise an empty array or dictionary, here is how its done. var todoItems = [String]() var todoItems = [String: Array]()

Conditionals

If statement

if condition1 {
} else if condition2 {
} else {
}

Switch

switch valueToCompareFrom {
case "value1":
// Do somethinghere
case "value2", "value3":
// Do something else
case let a where a.hasSuffix("novalue"):
// Handle it differently
default:
// This runs if none of the above case matches
}

Loops

For in loop

for item in arrayVar {
}

There are c like while and do-while loops also.

Functions

func myFunc(param1: String, param2: Int) -> String {
return "Hello \(param1), count \(param2)."
}
myFunc("John", 400)

Functions now can be nested. Functions are first class type and so a function can return another function and also can take another function as argument.

Classes and Inheritance

class Electronics: Thing {
var voltage = 220
init(volatge: Int) {
self.volatge = voltage
super.init()
}
func worksWithVolatge(volatge: Int) -> Bool {
return self.volatge == voltage
}
}
var computer = Electronics(100)
computer.voltage = 110
computer.worksWithVoltage(220) // returns false

Here class Electronics inherits from Thing class. init function is a constructor function Member variables can also have getters and setters. Static variables are defined using static keyword. Static functions are defined using class keyword.

Optional values

Optional values are a part of Apple’s type safety.

Gadget? is an optional type for Gadget class. It means that the instance variable is wrapped inside a construct which may return nil.

let optionalGadget: Gadget? = Gadget(voltage: 100)

You can’t access the the instance variable directly. You have to first unwrap it using the ? operator. If its nil then the assignment will fail. let voltage = optionalGadget?.voltage

Enums

enum iPhone: Int {
case Four = 1
case FourS, Five, FiveS, FiveC, Six, SixPlus
func printDescription() -> Void {
switch self {
default:
println(self.rawValue)
}
}
}

The value of a enum can be accessed by .rawValue property. Instance of an enumeration from a raw value can be made by following constructor. let iPhone5s = iPhone(rawValue: 4)

Extensions

As the name suggests it adds functionality to an existing class.

extension Int {
var simpleDescription: String {
return "The number \(self)"
}
mutating func adjust() {
self += 42
}
}
println(7.simpleDescription)


Warning: _() expects exactly 1 parameter, 2 given in /home2/mobilemeri7/public_html/wp-content/themes/mobilemerit/comments.php on line 28

Cracked Accounts Free Netflix Accounts VPN Proxy Shares Hack Programları Hack dökümanları Hack methodsları Wordlist Combolist Warez Scriptler Download Warez Files WhatsApp Numara çekme +90 Abazalardan Para kazanma Telegram Mavi tik alma 2022 Numara sorgulama Azuere Aws Sanal Kart Method WhatsApp vurma Güncel Method 2022 Bedava .Com .Org .Net VDS Premium Host YouTube Sahte Telif Methodu Tıklama hilesi ile para kazanmak Azure Hack method Pubg Mobile Uc Almak Hedef Kişinin herşeyini öğrenmek instagram Telif taslağı 2022 Ölüm Belgesi ile instagram hesap kaptma instagram form ile ebedi hesap kapatma instagram taklitsiz hesap kapatma instagram Çift faktör geçme instagram tiktok hesap çalma method instagram 2 Faktörlü doğrulama geçme instagram hesap kapatma 2022 instagram rever kırmak instagram Revert Kırma Abaza Dayı Methodu Aylık Dolar kazamak 1500 dolar instagram Çalmak istiyorum instagram düşmeyen takipçi instagram hackleme sitesi Whatsapp Kapatma %100 Abaza tokatlayarak para kazanmak Spotify ile para kazanma Günde 100 tl kazanma sınırsız kazanç Yatakta yatarak para kazanma YouTube izlenme arttırme yöntemi Oturduğun yerde para kazanma yöntemi Discord Hack tool Discord hack programları Cerebrus Rat v2 kodları PP Takipçi Çeken Telif Scripti Facebook profil kapatma methodu 2022 instagram yapay ile banned methodu instagram hesap satşı Sosyal medya hesap satışı Sosyal medya hack Leak Forum Crack Forum Cracking Forum Warez Forum Hack Forum illegal Forum Hacking Forum instagram Forum instagram Forumu Hacklink Hack forum php Shell indir Hack haber
https://www.ankihlasnakliyat.com/jigolosahibinden.comankara nakliyatankara nakliyatistanbul nakliyatankara nakliyatJigolodiyarijigolo sitesigerçek jigolo sitesijigolo sitelerimjigolo şirketlerijigolo sitelerijigolo başvurujigolo arayan kadınlara ulaşKocuceKo cuce