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
UIFont: family Thonburi | |
UIFont: font Thonburi-Bold | |
UIFont: font Thonburi | |
UIFont: font Thonburi-Light | |
UIFont: family Khmer Sangam MN | |
UIFont: font KhmerSangamMN | |
UIFont: family Snell Roundhand | |
UIFont: font SnellRoundhand-Black | |
UIFont: font SnellRoundhand-Bold | |
UIFont: font SnellRoundhand |
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 Cities: CaseIterable { | |
static var allCases: [Cities] { | |
return [.antwerp, .brussels, .mumbai, .hyderabad(countryName: "India")] | |
} | |
case antwerp | |
case brussels | |
case mumbai | |
case hyderabad(countryName: 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 CompassDirection: CaseIterable { | |
case north, south, east, west | |
} | |
print("There are \(CompassDirection.allCases.count) directions.") | |
// Prints "There are 4 directions." | |
let caseList = CompassDirection.allCases | |
.map({ "\($0)" }) | |
.joined(separator: ", ") | |
// caseList == "north, south, east, west" |
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 encrypt(_ string: String, with password: String) -> String { | |
#warning("This is terrible method of encryption") | |
return password + String(string.reversed()) + password | |
} | |
struct Configuration { | |
var apiKey: String { | |
#error("Please enter your API key below then delete this") | |
return "Enter your key here" | |
} | |
} |
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
#if false | |
#warning("this will not trigger a warning") | |
#error("this will not trigger an error") | |
#endif | |
#if true | |
#warning("this will trigger a warning") | |
#error("this will trigger an error") | |
#endif |
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
//generate a random number in the range 1 through 100 | |
let randomInt = Int.random(in: 1..<100) | |
let randomFloat = Float.random(in: 1..<100) | |
let randomDouble = Double.random(in: 1…100) | |
let randomCGFloat = CGFloat.random(in: 1…100) | |
//generate a random bool | |
let randomBoolean = Bool.random() |
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 groceryList = ["Milk", "Eggs", "Bread", "Nutella"] | |
if let randomGroceryItem = groceryList.randomElement() { | |
print("The random grocery item is \(randomGroceryItem)") | |
} | |
//The random grocery item is Milk |
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 names = ["Alejandro", "Camila", "Diego", "Luciana", "Luis", "Sofía"] | |
names.shuffle() | |
//names == ["Luis", "Camila", "Luciana", "Sofía", "Alejandro", "Diego"] | |
let numbers = 0…9 | |
let shuffledNumbers = numbers.shuffled() | |
// shuffledNumbers == [1, 7, 6, 2, 8, 9, 4, 3, 5, 0] |
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 = ["Sofia", "Camilla", "Martina", "Mateo", "Nicolás"] | |
let allHaveAtLeastFive = names.allSatisfy({ $0.count >= 5 }) | |
// allHaveAtLeastFive == 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
var numbers = [5, 6, 7, 8, 9, 10, 11] | |
numbers.removeAll(where: { $0 % 2 == 1 }) | |
// numbers == [6, 8, 10] |
OlderNewer