Collections of Swift

Advantages of collections:

  1. Save Time.
  2. Improves Understanding.
  3. Facilates Collaboration.
  4. Reduces Errors.
  5. Increase Productivity.
 var collectionArray = ["iOS", "Flutter", "iOS", "Android", "Web"]
collectionArray.map{$0.uppercased()}Output: ["IOS", "FLUTTER", "IOS", "ANDROID", "WEB"]
collectionArray.filter{$0 == "iOS"}Output: ["iOS", "iOS"]
Array(collectionArray.reversed())Output: ["Web", "Android", "iOS", "Flutter", "iOS"]
collectionArray.removeAll(where: {$0 == "iOS"})Output: ["Flutter", "Android", "Web"]
collectionArray.contains{$0 == "Web"}Output: true
collectionArray.firstIndex{$0 == "iOS"}Output: 0
collectionArray.lastIndex{$0 == "iOS"}Output: 2
collectionArray.max(){$0.count < $1.count}Output: Flutter
collectionArray.min(){$0.count < $1.count}Output: iOS
collectionArray.allSatisfy{$0 == "iOS"}Output: false
collectionArray.prefix(2)Output: ["iOS", "Flutter"]
collectionArray.suffix(2)Output: ["Android", "Web"]
collectionArray.popLast()Output: Web
collectionArray.removeLast()Output: Web
collectionArray.removeFirst()Output: iOS
collectionArray.remove(at: 2)Output: iOS
collectionArray.compactMap{$0 == "iOS"}Output: [true, false, true, false, false]
collectionArray.flatMap{$0 == "Android"}Output: [false, false, false, true, false]
Collections of swift

493 thoughts on “Collections of Swift

Leave a Reply

Your email address will not be published. Required fields are marked *