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
struct Car: Decodable { | |
let manufacturer: String | |
let model: String | |
} | |
struct Person: Decodable { | |
let name: String | |
let lastName: 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
let names = ["John", "Paul", "Peter", "Tim"] | |
let shuffledNames = names.shuffled() // returns an array of names in shuffled order. |
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 emptyCollection : [String] = [] | |
emptyCollection.randomElement() // retuns nil |
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 names = ["John", "Paul", "Peter", "Tim"] | |
names.randomElement()! | |
let playerNumberToName : [Int: String] = [9: "Lewandowski", 7: "Ronaldo"] | |
playerNumberToName.randomElement()! |
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 randomIntFrom0To20 = Int.random(in: 0 ..< 20) | |
let randomFloat = Float.random(in: 0 ..< 1) |
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 randomIntFrom1to10 = 1 + (arc4random() % 10) // return random number is the 1...6 |
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
struct City: Hashable { | |
let name : String | |
let state : String | |
let population : String | |
} | |
extension City : Hashable { | |
func hash(into hasher: inout Hasher) { | |
name.hash(into: &hasher) | |
state.hash(into: &hasher) | |
} |
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 isTheWeatherNice : Bool = true | |
print(isTheWeatherNice) // prints true | |
//now it's starts to rain | |
isTheWeatherNice.toggle() // it will change the bool value. | |
print(isTheWeatherNice) // prints 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
let s: Set<[Int?]> = [[1, nil, 2], [3, 4], [5, nil, nil]] | |
s.contains([1,nil,2]) // returns true |
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 arrayOfArrays = [[1,2],[3,4],[5,6]] | |
arrayOfArrays.contains([1,2]) // return false in Swift 4.1 | |
arrayOfArrays.contains([1,2]) // now it returns True because of fact that the elements in the array conforms to Equatable protocol |
NewerOlder