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 📧inbox = [ | |
"Don't miss this weekend's sale at Bob's Pizzeria!", | |
"Urgent: Production Database Backup Failed", | |
"Wednesday Developer Meetup Reminder" | |
] | |
while let 📧 = 📧inbox.popLast() { | |
print(📧) | |
} |
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 | |
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] | |
let url = documentsDirectory.appendingPathComponent("Closet Contents").appendingPathExtension("txt") | |
var closet = "👖x2 👕x5 👔x3 👟x2 👞x2" | |
do { | |
try closet.write(to: url, atomically: true, encoding: .utf8) | |
} catch { |
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 | |
@objcMembers class Craft: NSObject { | |
let name: String | |
let maxAltitude: Int | |
let maxSpeed: Int | |
init(name: String, maxAltitude: Int, maxSpeed: Int) { | |
self.name = name | |
self.maxAltitude = maxAltitude |
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 saturdayFoodLog = ["🍎": 2, "🥗": 2, "🥚": 3, "🥜": 20, "🍪": 2] | |
let sundayFoodLog = ["🥚": 1, "🥗": 1, "🍎": 1, "🍪": 1, "🌭": 2, "🥩": 1] | |
let weekendFoodLog = saturdayFoodLog.merging(sundayFoodLog) { $0 + $1 } | |
print(weekendFoodLog) // ["🥩": 1, "🥚": 4, "🥗": 3, "🍎": 3, "🥜": 20, "🌭": 2, "🍪": 3] |
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 👤: Identifiable { | |
static var peopleCount = 0 | |
let name: String | |
let height: Float | |
var id: String = { | |
Self.peopleCount += 1 | |
return "\(#function) \(Self.peopleCount)" | |
}() |
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 HexadecimalColor = UInt32 | |
let 🎨: HexadecimalColor = 0xFF872C // RGB(255, 135, 44) | |
let 🔴 = (🎨 & 0xFF0000) >> 16 // 255 | |
let 💚 = (🎨 & 0x00FF00) >> 8 // 135 | |
let 🔵 = 🎨 & 0x0000FF // 44 |
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 | |
let buffet = ["🍕", "🍔", "🌭", "🥗", "🌯", "🥘"] | |
let dinner = buffet.randomElement()! | |
print("Tonight I will eat \(dinner).") // Tonight I will eat 🍕. |
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 🚀Velocities = [700.55, 500.3, 1015.0, -50.0, -2000.25] | |
let maxVelocity = 🚀Velocities.reduce(0, Double.maximumMagnitude) | |
print("\(maxVelocity) mph") // -2000.25 mph |
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 binaryMessage = "101001011001000101111011110101011" | |
let 📞🔢 = Int(binaryMessage, radix: 2)! | |
print(📞🔢) // 5555550123 |
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 | |
let 🇺🇸🧊 = Measurement(value: 13, unit: UnitTemperature.fahrenheit) | |
let 🇬🇧🧊 = 🇺🇸🧊.converted(to: UnitTemperature.celsius) | |
print("It's \(Int(🇺🇸🧊.value))ºF or \(Int(🇬🇧🧊.value))ºC outside! 🥶") | |
// It's 13ºF or -10ºC outside! 🥶 |
NewerOlder