Skip to content

Instantly share code, notes, and snippets.

@kadiralev1
Created March 5, 2019 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kadiralev1/1dcf8871d769d1c3f0822a6972ce2905 to your computer and use it in GitHub Desktop.
Save kadiralev1/1dcf8871d769d1c3f0822a6972ce2905 to your computer and use it in GitHub Desktop.
var someInt = [Int]() // Boş array tanımlamak isterseniz tipini belirtmek zorundasınız.
// Şimdi default value kullanarak array oluşturalım.
var threeDoubles = Array(repeating: 2.5, count: 3)
print(threeDoubles) // [2.5, 2.5, 2.5]
// isEmpty fonksiyonu ile dizinin boş mu dolu mu olduğunu kontrol edebiliriz.
print(threeDoubles.isEmpty) // false --- bu fonksiyon geriye boolean tipinde bir değer döndürür. Gördüğünüz gibi bunda false döndü.
threeDoubles.insert(4, at: 3) // threeDoubles dizisinin 3.indexine 4 değerini koyduk.
print(threeDoubles) // [2.5, 2.5, 2.5, 4.0]
threeDoubles.remove(at: 3) // 3. index de ki değeri sildik
print(threeDoubles) // [2.5, 2.5, 2.5]
// Swiftin sağladığı güzelliklerden biri eğer hem indexe hemde değere ihtiyacımız varsa tuples şeklinde ikisinide alabiliriz.
var sehirArray = ["Ankara","İstanbul","İzmir","Antalya","Bursa"]
for (index,value) in sehirArray.enumerated() { // enumerated() metodu bize diziyi tuples olarak döndürür.
print("\(index+1). şehir : \(value)")
}
/*
yukarıdaki enumerated uygulanan dizinin çıktısı
1. şehir : Ankara
2. şehir : İstanbul
3. şehir : İzmir
4. şehir : Antalya
5. şehir : Bursa olacaktır.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment