This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func login(_ username:String , _ password:String) -> Bool { | |
if username == "swift" && password == "1234" | |
{ | |
return true | |
}else { | |
return false | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func birSeyYap(someInt:Int) -> Int { | |
return someInt * 2 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func cikarmaIslemi(sayi1:Int,sayi2:Int) -> Int { | |
return sayi1-sayi2 | |
} | |
cikarmaIslemi(sayi1:5 , sayi2:2) // sonuc 3 | |
// Şimdi aynı işi closure ile yapıyoruz | |
let closure : (Int , Int) -> Int = {(sayi1,sayi2) in | |
return sayi1-sayi2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var shortClosure : (Int , Int) -> Int = { | |
return $0 + $1 | |
} | |
shortClosure(5,3) // Sonuc 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var exampleArray = []() // Boş ve tipi belli olmayan bir array tanımladık. | |
var exampleArray2 = [Int]() // int tipinde veri tutan boş bir array tanımladık. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let colors = Set(["red","green","blue"]) | |
print(colors) // tamamen random sıralar. | |
/* | |
Yani ekranda | |
["green", "red", "blue"] | |
da çıkabilir | |
["blue", "green", "red"] | |
de çıkabilir | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var name = (first : "Kadir", last : "Alev") | |
// bu parametrelere erişmek içinse | |
print(name.0) // konsol'da Kadir yazar.(Parametre index'i ile bulundu.) | |
print(name.first) // konsol'da Kadir yazar. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ideAndLanguage = [String : String]() // Key'i ve value kısmı String olan boş bir dictionary tanımladık. | |
ideAndLanguage["XCode"] = "Swift" // XCode anahtarına ve Swift değerine sahip olan bir eleman tanımladık. | |
print(ideAndLanguage["XCode"]) // Konsolda Swift çıktısını alırız. Dictionary ' de değerlerimize key' leri kullanarak erişiriz. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Aşağıda rawValue tipi String olan bir enum tanımladık. | |
enum Gender : String { | |
case male = "Erkek" | |
case female = "Kadın" | |
} | |
print(Gender.male.rawValue) // çıktı olarak Erkek verecek. | |
// Dikkat rawValue kullanabilmek için enum'a tip verilmesini gerekir bu örnekte tipi String'tir. | |
// her ikisine de String değişken atamak zorunda degiliz. İstersek female kısmını boş bırakabiliriz ve şöyle kullanabiliriz | |
enum Gender : String { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Aktivite { | |
case oturmak | |
case kosmak (hedef : String) | |
case sarkiSoylemek(sarkiAdi : String) | |
} | |
let kos = Aktivite.kosmak(hedef: "Eve koş :D") | |
print(kos) // ekran çıktımız kosmak(hedef: "Eve koş :D") olacaktır. | |
// enumlar da alt alta gelen case' lerin sırasıyla değer almasını istiyorsak hepsine tek tek değer vermenize gerek yoktur. |