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
import Foundation | |
struct PreferenceKey<Value>: RawRepresentable { | |
typealias RawValue = String | |
let rawValue: RawValue | |
init (_ key: String) { | |
rawValue = key | |
} | |
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 HotDog { | |
var bun: String? | |
var meat: String? | |
var condiments: (chili: String?, cheese: String?, tomatoes: String?) | |
var ingredients: String { | |
[bun, meat, condiments.chili, condiments.cheese, condiments.tomatoes] | |
.compactMap { $0 } | |
.joined(separator: ", ") | |
} |
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
typealias Meal = (drink: String, food: String) | |
let drinks = ["🥛", "☕️", "🥤", "🍺", "🍷", "🍹"] | |
let foods = ["🍪", "🥓🍳", "🍔🍟", "🥜", "🍝", "🥗"] | |
let meals = Array(zip(drinks, foods)) as [Meal] | |
let dinner = meals[2] | |
print("Tonight, we will have \(dinner.drink) and \(dinner.food) for dinner.") | |
// Tonight, we will have 🥤 and 🍔🍟 for dinner. |
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
import Foundation | |
typealias AnimalGroup = (name: String, size: Int) | |
let animalGroups: [String: AnimalGroup] = [ | |
"🐬": ("pod", 12), | |
"🐺": ("pack", 6), | |
"🦒": ("tower", 10) | |
] |
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 Item { | |
let name: String | |
let isNecessary: Bool | |
let price: Int | |
} | |
var 🛒 = [ | |
Item(name: "📱", isNecessary: false, price: 600), | |
Item(name: "🧻", isNecessary: true, price: 10), | |
Item(name: "🍎", isNecessary: true, price: 5), |
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 🎒Items: OptionSet { | |
let rawValue: Int | |
static let 💻 = 🎒Items(rawValue: 1 << 0) | |
static let 📓 = 🎒Items(rawValue: 1 << 1) | |
static let 📷 = 🎒Items(rawValue: 1 << 2) | |
static let 🔦 = 🎒Items(rawValue: 1 << 3) | |
static let 🍎 = 🎒Items(rawValue: 1 << 4) | |
static let school: 🎒Items = [.💻, .📓] |
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
indirect enum Folder { | |
case 📁(label: String, contents: [Folder]) | |
case 📄(String) | |
} | |
let models = Folder.📁(label: "Models", contents: [.📄("Experience.swift")]) | |
let views = Folder.📁(label: "Views", contents: [.📄("MapperView.swift")]) | |
let controllers = Folder.📁(label: "Controllers", contents: [.📄("MainViewController.swift")]) | |
let xcodeProject = Folder.📁(label: "Business App", contents: [models, views, controllers]) |
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
import Foundation | |
struct 👤 { | |
var name: String | |
var comparisonName: String { | |
name.folding(options: [.diacriticInsensitive, .widthInsensitive, .caseInsensitive], | |
locale: .current) | |
} | |
} |
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
import Foundation | |
var 👨👩👧👦 = """ | |
Family: | |
Father's Name: Jayson | |
Mother's Name: Kathrine | |
Daughter's Name: Alannah | |
Son's Name: Jacob | |
""" |
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 Animal { | |
case 🐶, 🕷, 🐙, 🦁, 🐊 | |
} | |
var animals: [Animal] = [.🐶, .🕷, .🐶, .🐊, .🐙, .🐶, .🦁] | |
animals.removeAll { $0 != .🐶 } | |
if animals.allSatisfy({ $0 == .🐶 }) { | |
print("Yay! You removed all the scary animals!") | |
} |
OlderNewer